home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 1 / your choice.zip / your choice / OS2 / PROGFAQ / PROGFAQ.INF (.txt) < prev    next >
OS/2 Help File  |  1994-03-10  |  196KB  |  6,552 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Introduction and Credits ΓòÉΓòÉΓòÉ
  3.  
  4.             OS/2 2.x Frequently Asked Questions, Programmer's Edition
  5.  
  6.                            Version 3.0, March 4, 1994
  7.                            Compiled by Andreas Almroth
  8.  
  9.                        Pre-3.x versions by Jeff M. Garzik
  10.                         Pre-2.x versions by Barry Jaspan
  11.  
  12.                       Copyright (c) 1994 by Andreas Almroth
  13.                               All Rights Reserved.
  14.  
  15. For changes, suggestions, or additions please mail andreas@traci.almroth.pp.se 
  16. or write to: 
  17.  
  18. Andreas Almroth
  19. Apelgatan 2, 2tr
  20. S-602 15 NORRKOPING
  21. SWEDEN
  22.  
  23. Mention of a product does not constitute an endorsement.  Customers outside the 
  24. United States should not necessarily rely on 800 telephone numbers, page 
  25. numbers, part numbers, or upgrade policies contained in this List.  Electronic 
  26. mail addresses are in Internet form; use addressing appropriate to your mail 
  27. system. 
  28.  
  29. This FAQ is freely distributable for noncommercial purposes.  (For commercial 
  30. purposes, please contact the author.)  If you redistribute the FAQ, please 
  31. include all the original files. 
  32.  
  33. This FAQ is updated quarterly and is distributed through various computer 
  34. networks and online services, including the Internet and many BBSes. 
  35.  
  36. Both ASCII text and OS/2 Information Presentation Facility (INF) versions of 
  37. the FAQ are provided.  To view the INF version of the List, go to any OS/2 
  38. command line prompt (e.g. double click on "OS/2 Window") and type: 
  39.  
  40. VIEW PROGFAQ.INF
  41.  
  42. The ASCII text version may be viewed using any text editor, word processor, or 
  43. file listing utility.  The text version is intended to answer any questions you 
  44. may have before actually obtaining and using OS/2.  You will find that the INF 
  45. version provides a much more attractive interface, with hypertext links, fast 
  46. indexing, and, increasingly, illustrations. 
  47.  
  48. If you have not received all three files (README.CMD, PROGFAQ.INF, and 
  49. PROGFAQ.TXT), please ask your system operator to make sure he/she is receiving 
  50. the correct and complete package every month. 
  51.  
  52. Many of the answers in this FAQ refer to anonymous ftp site FTP-OS2.CDROM.COM 
  53. (192.153.46.2). The name 'cdrom.com' is used as a shorthand to refer to this 
  54. site.  It has become, by default, the Internet storehouse for OS/2 files.  If 
  55. you cannot get files from this site (for whatever reason), then check OS/2 
  56. Software Sources for a source near you. You may find a more convenient method 
  57. of getting files than from cdrom.com.  (Non-US readers will note Bjorn 
  58. Fahller's FTP site, ftp.luth.se, is the main overseas FTP site.) 
  59.  
  60.  
  61. Related Information:
  62.  
  63. Release Notes
  64. OS/2 Software Sources
  65. Obtaining this FAQ / Contacting the Author
  66.  
  67.  
  68. ΓòÉΓòÉΓòÉ 2. Release Notes ΓòÉΓòÉΓòÉ
  69.  
  70. Text which has been revised or updated since the last release will appear in 
  71. the same color as this paragraph. 
  72.  
  73. Version 3.0:  A new maintainer of the OS/2 Programming FAQ: Andreas Almroth 
  74.  
  75. Some answers changed or added. 
  76.  
  77. Version 2.3:  This release does not include very many new sections, but the 
  78. information has been reorganized for greater readability and easier maintenence 
  79. (for me).  Major changes include title re-wording for brevity, revision 
  80. coloring, and updated information. 
  81.  
  82.  
  83. Related Information:
  84.  
  85. Introduction and Credits
  86. OS/2 Software Sources
  87. Obtaining this FAQ / Contacting the Author
  88.  
  89.  
  90. ΓòÉΓòÉΓòÉ 3. Questions Covered in this Release ΓòÉΓòÉΓòÉ
  91.  
  92. Languages, Compilers, Debuggers
  93.   What programming languages come with OS/2?
  94.   Programming language availability
  95.   Which of these compilers can be used to generate PM apps?
  96.   Which assemblers can produce OS/2 32-bit code?
  97.   The two GNU C/C++/ObjC packages
  98.   What is REXX?  How do I write and run a REXX program?
  99.   What debuggers are available for OS/2?
  100. Tools, Toolkits, Accessories
  101.   How do I use PATCH, maybe with my own programs?
  102.   What programming editors are available for OS/2?
  103.   What programming tools/toolkits/accessories are available for OS/2?
  104.   What GNU tools are available and where can I find them?
  105.   Is a socket library available?  How can I use it?
  106. Compiling
  107.   Can I distribute the C-Set++ runtime DLL?
  108.   How big should my stacksize be?
  109.   How do I determine what C/C++ compilator is compiling my code?
  110.   How do I perform parallel compilation?
  111.   What is an RC of 87 (invalid param) from the API?
  112.   GCC/2 crashes with a trap when I try to compile a program.  Why?
  113.   How do I recompile EPM (easily)?
  114.   How to I get BC++ for DOS/Windows to run?
  115. Documentation, Help
  116.   Where can I get information on OS/2 APIs and programming?
  117.   Where can I get sample code?
  118.   Are there any OS/2 programming classes or seminars?
  119.   What are good ref. books for programming in OS/2 and PM?
  120.   What are good OS/2 programming magazines?
  121.   What are the OS/2 redbooks, and how do I get them?
  122.   How can I view the GNU C documentation?
  123.   Where can I get documentation on the OBJ/LIB/EXE format used by OS/2 2.x?
  124.   Where can I find information on HPFS?
  125. PM Programming
  126.   Printing
  127.     Are there any SIMPLE examples of printing?
  128.     Is there an easy way to get printer output (another opinion)?
  129.     How do I print a bitmap?
  130.     How do I do my own Print Screen?
  131.   Menus
  132.     How do I add a menu to a dialog box?
  133.     How do I make a dynamically changing menu?
  134.     How do I create a conditional cascade menu?
  135.     How do I remove a separator from a menu?
  136.   Container Controls
  137.     How do I stop a container from flashing every time I add a record?
  138.     How do I get my containers to use Mini-icons?
  139.     How do I sort a container control?
  140.     How do I query all records in a container - tree view?
  141.   I can't get different colors in text control windows
  142.   How can I toggle my titlebar on and off?
  143.   How can I get transparent regions in bitmaps?
  144.   How do I create a status bar at the bottom of my window?
  145.   How to have a frame/client and still have a std window?
  146.   How do I use printf() in a PM program?
  147.   I have a SOM DLL. How do I register it?
  148.   How do I save and restore my window size and position?
  149.   How do you make a window float above all other?
  150.   How to ensure the sizing's correct so the dlg "fits" in the notebook...?
  151.   How do I prevent Shutdown from stopping my app?
  152.   When I pass a structure to WinCreateWindow, sometimes it doesn't work!
  153.   How do I use type filtering in 2.0's open dlg?
  154.   When minimizing, my dialog box is overwriting my icon!
  155.   How do I make a multi-column listbox?
  156.   How do I create my own Master Help Index?
  157.   How do I change the font in an MLE?
  158.   How do I attach Instance data to window created with WinCreateStdWindow?
  159.   How do I get a list of fonts?
  160.   How do I create a folder in C and put my pgm in it?
  161.   How do I do it in REXX?
  162.   How do I use the Font dialog (WinFontDlg)?
  163.   How do I take control of frame sizing?
  164.   How do I use the 16-bit EPM toolkit?
  165.   How do I get error info after using WinGetLastError()?
  166.   Do you have code to save/restore the clipboard?
  167.   How do I know what item was selected in a Combo box?
  168.   How do I get a bitmap into a dialog in a DLL?
  169.   How does programming PM compare to programming X?
  170.   How do I put bitmaps on buttons?
  171.   Can a PM program tell if there's a previous instance of itself running?
  172. Miscellaneous Programming
  173.   Explain the SYS_DLL keywords.
  174.   How do I start another session?
  175.   How do I check if a filename is valid?
  176.   Why should I use _beginthread instead of DosCreateThread?
  177.   How do I open a file that is already in use?
  178.   Can we use Vio in v2.0? Where are the docs for it?
  179.   Can I redirect stdin and stdout in a child process?
  180.   How do I use DosMon*() to stuff the kbd buf?
  181.   How do I determine what file system a drive uses?
  182.   How do I get the error message from a DOS API call?
  183.   How do I set an exception handler?
  184.   How can I determine a diskette format and if a disk is in a drive?
  185.   What do all those keywords mean when making a DLL?
  186.   Where can I find serial port sample code?
  187.   How do I disable <Ctrl><Alt><Del>?
  188.   Why doesn't printf() produce output when I expect it to?
  189.   How do I write an OS/2 device driver?
  190.   How do I change the master environment?
  191.   What is the best way to communicate between processes?
  192.   What is the best way to communicate between threads?
  193.   How to I write an IFS?
  194.   How do I interface with OS/2's SCSI support?
  195.   How do I program full-screen graphics?
  196.   How do I program MMPM/2 programs?
  197.   How do I peripheral memory or an I/O port?
  198. Porting
  199.   How do I port my DOS keyboard TSR to OS/2?
  200.   How can I simulate (Unix feature) under OS/2?
  201.   How can I recompile public domain/shareware source code for OS/2?
  202.   How can I port my DOS program to OS/2?
  203.   How can I port my Windows program to OS/2?
  204. Miscellaneous
  205.   Is OS/2 suitable for real time programs?
  206.   What is available for multimedia programming under OS/2?
  207.   What is available for AI/neural net programming under OS/2?
  208.   Special software offers
  209.   Technical Support
  210.   Developer's Assistance Program (DAP)
  211.  
  212.  
  213. ΓòÉΓòÉΓòÉ 4. Languages, Compilers, Debuggers ΓòÉΓòÉΓòÉ
  214.  
  215. This section covers the programming tools currently available for OS/2.  The 
  216. following topics are available: 
  217.  
  218. What programming languages come with OS/2?
  219. Programming language availability
  220. Which of these compilers can be used to generate PM apps?
  221. Which assemblers can produce OS/2 32-bit code?
  222. The two GNU C/C++/ObjC packages
  223. What is REXX?  How do I write and run a REXX program?
  224. What debuggers are available for OS/2?
  225.  
  226.  
  227. ΓòÉΓòÉΓòÉ 4.1. What programming languages come with OS/2? ΓòÉΓòÉΓòÉ
  228.  
  229. The original BASIC and BASICA (for systems with BASIC in ROM, mainly IBM 
  230. systems), DOS's QBASIC, and OS/2's REXX comes with OS/2 2.x. 
  231.  
  232. REXX is basically the official command language of OS/2. 
  233.  
  234.  
  235. Related Information:
  236.  
  237. What is REXX?  How do I write and run a REXX program?
  238.  
  239.  
  240. ΓòÉΓòÉΓòÉ 4.2. Programming language availability ΓòÉΓòÉΓòÉ
  241.  
  242. Virtually all of them: Assembler, C, C++, COBOL, Pascal, Fortran, Smalltalk, 
  243. Modula-2, LISP, Forth, Perl, and more.  The OS/2 Tools Guide on cdrom.com 
  244. (os2/all/info/tinf34.zip) contains information on these and more.  Also check 
  245. the User's Edition for information on IBM's Development Tools Guide.  It's a 
  246. free catalog from IBM. 
  247.  
  248. All prices listed are "list price," as listed in Fall/Winter Programmer's 
  249. Paradise catalog.  All entries marked "Freely Available" can be obtained from 
  250. cdrom.com unless otherwise noted. 
  251.  
  252.  1. Ada 
  253.  
  254.    o GNU Ada 1.67 for OS/2; freely available; under development; cs.nyu.edu in 
  255.      the pub/gnat directory.  Needs GCC/2 to compile applications written in 
  256.      Ada. 
  257.    o Alsys AdaWorld OS/2 
  258.  
  259.  2. Assembly Language 
  260.  
  261.    o IBM Macro Assembler, $288 
  262.    o GNU assembler v1.38, included in emx/gcc 0.8h package 
  263.    o GNU assembler v1.38, included in GCC/2 v2.5.4 package 
  264.    o Turbo Assembler v3.21, included in Borland C++ for OS/2 package 
  265.  
  266.  3. BASIC 
  267.  
  268.    o CA-REALIZER, $295 
  269.    o ObjectView PM Basic, $899 
  270.  
  271.  4. C/C++ 
  272.  
  273.    o Borland C++ for OS/2 v1.00, $495 
  274.    o CA-C++ for OS/2, $449 
  275.    o emx/gcc 0.8h (gcc v2.5.7), freely available 
  276.    o GCC/2 v2.4.5, freely available 
  277.    o IBM C-Set++ FirstStep (without optimization) $??? 
  278.    o IBM C-Set++, $595 
  279.    o Objective C, $249 (not to be confused with the Objective-C language 
  280.      included free with emx/gcc and GCC/2) 
  281.    o TopSpeed C Pro, $297 
  282.    o TopSpeed C Standard, $198 
  283.    o WATCOM C/C++ 16 9.5, $495 
  284.    o WATCOM C/C++ 32 9.5, $599 
  285.  
  286.  5. CSP 
  287.  
  288.    o IBM CSP/2, $??? 
  289.  
  290.  6. COBOL 
  291.  
  292.    o MicroFocus COBOL, $??? 
  293.  
  294.  7. FORTRAN 
  295.  
  296.    o f2c [Fortran to C translator], freely available 
  297.    o IBM Fortran/2 OS/2, $761 
  298.    o WATCOM FORTRAN 77 16 9.5, $495 
  299.    o WATCOM FORTRAN 77 32 9.5, $599 
  300.  
  301.  8. LISP 
  302.  
  303.    o CLISP, freely available (ma2s2.mathematik.uni-karlsruhe.de) 
  304.    o XLisp, freely available 
  305.  
  306.  9. Pascal 
  307.  
  308.    o Borland Pascal v7.0, $495 (requires patch) 
  309.    o MicroWay, $??? 
  310.    o Power Pascal/2, freely available, req. MASM 6.00 
  311.    o p2c [Pascal to C translator], freely available 
  312.    o pasos2, freely available, supports EMX/GCC (ftp.eb.ele.tue.nl) 
  313.    o TopSpeed, $??? 
  314.  
  315. 10. PERL 
  316.  
  317.    o GNU PERL v4.0pl36, freely available 
  318.  
  319. 11. PL/I 
  320.  
  321.    o IBM PL/I for OS/2 
  322.  
  323. 12. Modula-2 
  324.  
  325.    o TopSpeed, $??? 
  326.    o Stonybrook, $??? 
  327.  
  328. 13. Scheme 
  329.  
  330.    o XScheme for OS/2, freely available 
  331.  
  332. 14. SmallTalk 
  333.  
  334.    o SmallTalk/V PM, $995 
  335.    o Parc Place Smalltalk, $??? 
  336.  
  337.  
  338. RelatedInformation :
  339.  
  340. The two GNU C/C++/ObjC packages
  341.  
  342.  
  343. ΓòÉΓòÉΓòÉ 4.3. The two GNU C/C++/ObjC packages ΓòÉΓòÉΓòÉ
  344.  
  345. The two versions of GNU C that are available were ported to OS/2 with different 
  346. goals and philosophies in mind and therefore have different characteristics. 
  347. However, both systems include a fairly complete C library and can be used to 
  348. compile useful programs, although their support of Unix-specific semantics 
  349. differs.  Furthermore, both systems are being actively developed and are 
  350. constantly improving. 
  351.  
  352. The goal of GCC/2 is to create a pure, freely redistributable OS/2 2.x 
  353. development environment.  It is based on GNU C 2.5.4, supports C, C++, and 
  354. Objective C, and can create PM programs.  It produces "native" 32 bit .OBJ 
  355. files that are linked with OS/2's LINK386.EXE, and can be linked together with 
  356. .OBJ files produced by IBM C-Set++ and other compatible compilers.  The mailing 
  357. list os2gcc@netcom.com exists for discussion of this port; send mail to 
  358. os2gcc-request@netcom.com for subscription information. 
  359.  
  360. emx/gcc 0.8h, based on GNU C 2.5.7, supports C, C++, and Objective C and can 
  361. create PM programs.  emx's goal is to make porting Unix programs easier by 
  362. emulating Unix semantics as closely as possible. It produces programs that can 
  363. run under OS/2 using EMX.DLL, it produces programs that can run under OS/2 
  364. without any DLL requirements (linked with OS/2's LINK386), and it can produce 
  365. MS-DOS 32-bit executables (emx.exe DOS extender required for MS-DOS 
  366. executables).  emx/gcc uses standard Unix development tools like ld and nm, and 
  367. fully supports Unix-isms like select() and fork().  A version of gdb exists 
  368. that can debug emx/gcc programs. An emx-related mailing list exists; send mail 
  369. to LISTSERV@eb.ele.tue.nl with a message body of "help" for subscription 
  370. information. 
  371.  
  372.  
  373. ΓòÉΓòÉΓòÉ 4.4. Which of these compilers can be used to generate PM apps? ΓòÉΓòÉΓòÉ
  374.  
  375. Basically, all the compilers except the following can generate PM applications: 
  376.  
  377. o CLISP 
  378. o XLisp 
  379. o PERL 
  380. o XScheme 
  381.  
  382.  
  383. ΓòÉΓòÉΓòÉ 4.5. What is REXX?  How do I write and run a REXX program? ΓòÉΓòÉΓòÉ
  384.  
  385. REXX is the IBM SAA (Systems Application Architecture) standard, user-friendly 
  386. programming language.  It is available for IBM mainframes, Unix, the Amiga, DOS 
  387. (Quercus's Personal REXX), Windows, and other platforms.  It has been a part of 
  388. standard OS/2 since Version 1.3.  Programs written in REXX that do not use 
  389. system-specific libraries are fully portable. 
  390.  
  391. OS/2 2.x comes with an online REXX reference, and printed REXX documentation is 
  392. available (Mike Cowlishaw's REXX book, IBM's twin guides).  The Usenet group 
  393. comp.lang.rexx discusses REXX programming. 
  394.  
  395. It should be stressed, however, that OS/2's online REXX reference is a 
  396. reference, not really a tutor.    Paul Prescod 
  397. (papresco@undergrad.math.uwaterloo.ca) is working on a free REXX tutor, which 
  398. will be available on cdrom.com. 
  399.  
  400. Watcom also makes VX REXX and Hockware makes VisPro/REXX.  Both of these 
  401. products allow quick and easy development of REXX PM programs. 
  402.  
  403.  
  404. ΓòÉΓòÉΓòÉ 4.6. What debuggers are available for OS/2? ΓòÉΓòÉΓòÉ
  405.  
  406. IPMD, a PM-based debugger, ships with C-Set++.  It is capable of source- and 
  407. assembly-level debugging multithreaded 16 bit and 32 bit OS/2 applications 
  408.  
  409. emx/gcc comes with gdb 4.11, the GNU debugger. 
  410.  
  411. Borland C++/2 comes with a PM-based debugger called Turbo Debugger GX which has 
  412. the same basic functionality as IPMD. 
  413.  
  414. There are also several commercial debuggers on the market.  WATCOM C and 
  415. FORTRAN come with WVIDEO, a full-screen source or assembly level debugger that 
  416. handles multithreaded 16 and 32 bit OS/2 programs. Multiscope (no longer 
  417. available for 32-bit OS/2) and Periscope are others.  CodeView is still 
  418. applicable for 16-bit OS/2 apps, but it is not recommended for 32-bit apps. 
  419.  
  420.  
  421. ΓòÉΓòÉΓòÉ 4.7. Which assemblers can produce OS/2 32-bit code? ΓòÉΓòÉΓòÉ
  422.  
  423. o Masm 5.2 and 6.0 can produce 32 bit, 2.x compatible code. 
  424. o Masm 6.1 no longer supports OS/2. 
  425. o Tasm 1.0 (OS/2) generates 2.x code, when proper options are given. 
  426. o Tasm 3.2 (DOS) can produce OS/2 compatible .OBJ files with the /oi option. 
  427. o IBM has an assembler for 2.x, but they won't release it to the public. 
  428.  
  429.  
  430. ΓòÉΓòÉΓòÉ 5. Tools, Toolkits, Accessories ΓòÉΓòÉΓòÉ
  431.  
  432. This section covers tools, toolkits, and accessories available to OS/2 
  433. programmers. 
  434.  
  435.  
  436. ΓòÉΓòÉΓòÉ 5.1. How do I use PATCH, maybe with my own programs? ΓòÉΓòÉΓòÉ
  437.  
  438. The file format is actually quite simple - you just need a text file which 
  439. consists of lines each starting with one of the following commands: 
  440.  
  441.   FILE <filename>     e.g. FILE test.exe 
  442.  
  443. specifies the file to which the following instructions are to be applied. A 
  444. patch file may contain multiple FILE directives. 
  445.  
  446.   VER <offset> <data>   e.g. VER 00001234 abcdef 
  447.  
  448. checks if the specified data is present at the given file offset [all values in 
  449. hex, data can be just a string of digits with no blanks in between; up to 16 
  450. bytes are allowed in one statement]. If the check fails, the patch process is 
  451. aborted resp. the program skips to the next FILE statement. 
  452.  
  453.   CHA <offset> <data>   e.g. CHA 00001234 012345 
  454.  
  455. changes the data at the given offset - syntax is same as in VER. It is a good 
  456. idea to do all VERification before starting the first CHA. 
  457.  
  458. Blank lines and data lines starting with a ";" are ignored. 
  459.  
  460. As you can see from this, there seems to be no way to _insert_ or _delete_ 
  461. bytes in the file. To make patches applicable to multiple versions of the same 
  462. file, you can specifiy more than one FILE directive for the same filename - 
  463. only a patch with all VER commands matching is executed. 
  464.  
  465. Credit:  Marcus Groeber 
  466.  
  467.  
  468. ΓòÉΓòÉΓòÉ 5.2. What programming editors are available for OS/2? ΓòÉΓòÉΓòÉ
  469.  
  470. OS/2 2.x comes with the Enhanced Editor (EPM). 
  471.  
  472. GNU Emacs 19.22 is available.  It supports PM and text mode programming. Emacs 
  473. is available on cdrom.com in os2/2_x/unix/gnu/emacs.  (If you want to recompile 
  474. emacs, you will need the full emx distribution; see question 1.2.) Also, you 
  475. must have HPFS installed to use GNU emacs.    You can read, write, and edit files 
  476. that exist on a DOS partition, but you must have GNU emacs installed on an HPFS 
  477. partition. 
  478.  
  479. Several public-domain vi clones are available, including elvis, Stevie and 
  480. levee.  The MKS Toolkit also includes vi. 
  481.  
  482. Many other text editors are available. 
  483.  
  484. Epsilon, by Luguru, (412) 421-5678.  DOS upgrade to OS/2 is $90.  Character 
  485. based editor. 
  486.  
  487. Q-Edit, by SemWare, (404) 641-9002.  Character based editor, almost identical 
  488. to Q-Edit for DOS.  Does not support long filenames yet. 
  489.  
  490. Brief, KEDIT, others? [Vendors, phone numbers, prices?] 
  491.  
  492. EHP, a text mode editor, was recently ported by Axel Uhl to PM, and is 
  493. available on cdrom.com. 
  494.  
  495. THE (The Hessling Editor), is a free text-mode editor, based on IBM's VM/CMS 
  496. XEDIT and Mansfield Software's KEDIT.  THE has full REXX macro capabilities. 
  497. Versions also exist for DOS and most Unices. 
  498.  
  499.  
  500. ΓòÉΓòÉΓòÉ 5.3. What programming tools/toolkits/accessories are available for OS/2? ΓòÉΓòÉΓòÉ
  501.  
  502. C-Set++ includes the following tools (excluding the compiler & debugger 
  503. themselves): 
  504.  
  505. o EXTRA - Execution trace analyzer 
  506. o A Class browser 
  507.  
  508. The IBM Programmer's Toolkit, included in Workset/2 and also in C-Set++, 
  509. includes many tools: 
  510.  
  511. o A dialog editor 
  512. o A SOM compiler 
  513. o A font editor 
  514. o An icon editor 
  515. o An IPF compiler 
  516. o Message compile & bind tools 
  517. o Resource compile & bind tools 
  518. o KwikInf 
  519. o ...and a couple others 
  520.  
  521. Borland C++ for OS/2 also includes a number of utilities, such as the Resource 
  522. Workshop. 
  523.  
  524. The MKS Toolkit, available from MKS ($299 USD, 800-265-2797 or 
  525. inquiry@mks.com), has over 160 Unix tools, including Korn shell, tar, vi, awk, 
  526. grep, tail, cpio, and so forth.  It also contains a Lex and Yacc capable of 
  527. generating C, C++, and Turbo Pascal code. 
  528.  
  529. There is a product called ARGO/UX which provides a BSD environment for OS/2. 
  530. [details?] 
  531.  
  532. SOFTPRO GmbH has announced its 32bit C++ class library TOUCH-GUI 2.0 for OS/2 
  533. 2.x. 
  534.  
  535.  
  536. ΓòÉΓòÉΓòÉ <hidden> TOUCH-GUI 2.0 for OS/2 2.x ΓòÉΓòÉΓòÉ
  537.  
  538. SOFTPRO GmbH has announced its 32bit C++ class library TOUCH-GUI 2.0 for OS/2 
  539. 2.x. The product contains more than 130 classes which support windows, menu 
  540. bars, multi-threading, controls, dialog boxes, graphics, printer control, MDI, 
  541. DDE, Drag and Drop, loadable resources from DLL's, and management of profiles 
  542. (.INI files). Other features include auxiliary classes for data manipulation 
  543. and storage management. Additionally, TOUCH-GUI 2.0 contains high-level classes 
  544. like toolbars, formatted entry fields, tables, and complete NLS. 
  545.  
  546. Supported C++ compilers are: Borland, GNU (emx), IBM, and WATCOM 
  547.  
  548. The product includes online (.INF) and printed documentation, a demo program, 
  549. and samples. 
  550.  
  551. TOUCH-GUI 2.0 costs DM 1.720,00 excl. VAT (ca. $1075), the runtime DLL's may be 
  552. distributed royalty free. Special project licenses are available, contact the 
  553. supplier. 
  554.  
  555. Contact:
  556. SOFTPRO GmbH, Stadtgrabenstr. 21, 71032 Boeblingen, Germany
  557. Tel.: +49 7031 6606-0
  558. Fax: +49 7031 6606-66
  559. Mr. Frank Fuchs (extension -50)
  560. Internet email: ffu@softpro.de
  561. IBMMAIL (IEA): DEJP9SK9
  562.  
  563.  
  564. ΓòÉΓòÉΓòÉ 5.4. What GNU tools are available and where can I find them? ΓòÉΓòÉΓòÉ
  565.  
  566. Nearly all the GNU utilities have been ported to OS/2 2.x - and nearly all of 
  567. those ports are located on cdrom.com in os2/2_x/unix/gnu. Other, more involved 
  568. (or independent) ports of GNU software is scattered about cdrom.com, including 
  569. a PM version of GhostView and GhostScript. 
  570.  
  571.  
  572. ΓòÉΓòÉΓòÉ 5.5. Is a socket library available?  How can I use it? ΓòÉΓòÉΓòÉ
  573.  
  574. IBM's TCP/IP 2.0 ($200) includes an optional Programmer's Toolkit ($500, part 
  575. #02G6973).  It includes a socket library, and support for Sun RPC, NCS RPC, and 
  576. a limited Kerberos capability.  It requires IBM C-Set++ or another compiler 
  577. that understands 16-bit code.  The 32-bit version is in beta right now. 
  578. (contact IBM for details) 
  579.  
  580. For REXX programs there is a socket library called REXXSOCK available from 
  581. cdrom.com as os2/ibm/ews/rxsock.zip.  It can be used to write TCP/IP 
  582. applications such as Gopher, IRC, etc. 
  583.  
  584. FTP Software, Inc., has an OS/2 version of its TCP/IP product.  They can be 
  585. reached at (617) 246-0900 or info@ftp.com. 
  586.  
  587. If you have the IBM TCP/IP 2.0 base package and IBM C-Set++, you can use the 
  588. TCPIPDLL.DLL directly. 
  589.  
  590.  
  591. ΓòÉΓòÉΓòÉ 6. Compiling ΓòÉΓòÉΓòÉ
  592.  
  593. This section covers compiling OS/2 programs and accessories.  The following 
  594. topics are available: 
  595.  
  596. Can I distribute the C-Set++ runtime DLL?
  597. How big should my stacksize be?
  598. How do I perform parallel compilation?
  599. What is an RC of 87 (invalid param) from the API?
  600. GCC/2 crashes with trap when I try to compile a program. Why?
  601. How do I recompile EPM (easily)?
  602. How to I get BC++ for DOS/Windows to run?
  603.  
  604.  
  605. ΓòÉΓòÉΓòÉ 6.1. Can I distribute the C-Set++ runtime DLL? ΓòÉΓòÉΓòÉ
  606.  
  607. Yes, you can! (But it is not as simple as that really...) 
  608.  
  609. You can not distribute the runtime DLL that comes with C-Set++ in its native 
  610. form, you must rebuild the DLLs you want to distribute and delete functions in 
  611. the .DEF files, so that your DLL files only contains functions your program 
  612. need. Read more about this topic in C/C++ Tools - Programming Guide pages 
  613. 195-222, that comes with C-Set++ (2.x). 
  614.  
  615.  
  616. ΓòÉΓòÉΓòÉ 6.2. How do I determine what C/C++ compilator is compiling my code? ΓòÉΓòÉΓòÉ
  617.  
  618. If your source code is written for several compilers, one need to know what 
  619. uniqe defines these compilers use.  IBM C/C++         __IBMCPP__ Borland C++ 
  620. for OS/2   __BORLANDC__ EMX/GCC          __EMX__ 
  621.  
  622.  
  623. ΓòÉΓòÉΓòÉ 6.3. How big should my stacksize be? ΓòÉΓòÉΓòÉ
  624.  
  625. o For non-PM programs: At least 8k for every thread. 
  626. o It is critical to avoid stack sizes where byte 2 has a value of 2 or 4, e.g.: 
  627.  
  628.    0x00020000 (128k) 
  629.    0x00040000 (256k) 
  630.    0x33023678 
  631.    0x11041111 
  632.  
  633. Otherwise, when executing under OS/2 2.0GA there may be various and always 
  634. differing runtime error behaviors.  (This is documented in OMF.INF, an online 
  635. reference from IBM concerning OBJ/EXE file formats for 16 and 32 bits.) 
  636.  
  637.  
  638. ΓòÉΓòÉΓòÉ 6.4. How do I perform parallel compilation? ΓòÉΓòÉΓòÉ
  639.  
  640. You can accomplish parallel compilation in one of two ways. The first involves 
  641. GNU Make, the second involves DMAKE. 
  642.  
  643. GNU Make: 
  644.  
  645. To perform parallel compilation with GNU Make simply do two things: 
  646.  
  647. o Make sure your make file does not execute the make utility (again) from 
  648.   inside the make file. 
  649. o On the GNU Make command line, specify '--jobs x', where 'x' is the maximum 
  650.   number of concurrent jobs you will allow GNU Make to execute. If you do not 
  651.   wish to have a maximum, then you may specify simply '--jobs' and GNU Make 
  652.   will execute as many jobs as possible at one time. 
  653.  
  654. DMAKE: 
  655.  
  656. The ini file comes in the dmake archive in a few different flavours.  Take the 
  657. file with the extension .msc and rename it to dmake.ini.  Set an environment 
  658. variable in config.sys 
  659.  
  660. SET MAKESTARTUP=d:\COMPILER\DMAKE.INI 
  661.  
  662. ====== Makefile 
  663.  
  664. CC=icc
  665. COPTS=/Sm /Gt+ /Ti+ /O- /Gs+
  666. CONLY=-c
  667.  
  668. LIBS=os2
  669.  
  670. INCS=psfax2.h
  671.  
  672. MAXPROCESS=2
  673.  
  674. all: psfax2.exe sendfax.exe
  675.  
  676. modem.obj:  modem.c $(INCS)
  677.    $(CC) $(CONLY) $(COPTS) modem.c
  678.  
  679. psfax2.obj: psfax2.c $(INCS)
  680.    $(CC) $(CONLY) $(COPTS) psfax2.c
  681.  
  682. psfax2.exe: psfax2.obj modem.obj
  683.    link386 /ST:32768 /CO psfax2+modem;
  684.  
  685. sendfax.obj: sendfax.c $(INCS)
  686.    $(CC) $(CONLY) $(COPTS) sendfax.c
  687.  
  688. sendfax.exe: sendfax.obj modem.obj
  689.    link386 /ST:32768 /CO sendfax+modem;
  690.  
  691. ====== End of makefile 
  692.  
  693. Couple of gotchas.  There is a bug in the MAXPROCESS handling of the copy I 
  694. use.  Set it to 1, and you get a typical make, ie one at a time. Set it to 2, 
  695. and the thing launches 3 processes. Ie with more than 1, you actually get n+1 
  696. processes running. 
  697.  
  698. Another caveat 
  699.  
  700. xxx.yy: aaa.bbb
  701.     command1
  702.     command2
  703.     command3
  704.  
  705. The above structure does not work.  The reason is that all 3 commands will be 
  706. spawned together in parallel sessions.  To serialize them you must make up 
  707. dependancies in the makefile.  I ran into this becuase I have one makefile that 
  708. completes every link stage by copying the result onto a network drive.  I had 
  709. to take all the links that previously had 2 commands, and break them into 2 
  710. blocks with the second being a dependancy of the remote file on the local file, 
  711. and the copy command. 
  712.  
  713. One more word of warning, dmake is not to pleased with those convoluted things 
  714. that workframe spits out in the name of makefiles.  You may have to do a 
  715. significant amount of makefile editing, depending on how you makefile look now. 
  716.  
  717. Provided that 3 simultaneous copies of your compiler doesn't push your machine 
  718. into excessive swapping, the improvements in build speed are amazing.  Before 
  719. dmake I'd never seen a build actually top the cpu meter here, the process was 
  720. always waiting for disk as it loaded compilers/headers etc.    Now the compiler 
  721. sits in ram and just gets re-used, and the headers are coming directly from 
  722. cache all the time. Build time cut in half, and my cpu guage is pegged at 100% 
  723. when a build is running. 
  724.  
  725.  
  726. ΓòÉΓòÉΓòÉ 6.5. What is an RC of 87 (invalid param) from the API? ΓòÉΓòÉΓòÉ
  727.  
  728. You are (most likely) not including the prototype.  Use the following flags to 
  729. get a good balance of warning messages: 
  730.  
  731.     /Kbperc 
  732.  
  733. For C Set++, I use these flags as the approximate equivalent 
  734.  
  735.     /Wall /Wext- /Wgnr- /Wgot- /Wpor- /Wppt- /Wtrd /Wuni- /Wvft- 
  736.  
  737. I have these set as part of my ICC string in CONFIG.SYS, so I don't have to add 
  738. them to each compile.  I have found that these settings give me a good 
  739. combination of thorough warning messages without too many warnings. 
  740.  
  741.  
  742. ΓòÉΓòÉΓòÉ 6.6. GCC/2 crashes with a trap when I try to compile a program.  Why? ΓòÉΓòÉΓòÉ
  743.  
  744. Because you didn't read the README or INSTALL files, probably.  There are three 
  745. general reasons GCC/2 will crash: 
  746.  
  747.  1. You did not set up the environment variables in CONFIG.SYS properly.  Read 
  748.     doc/INSTALL for instructions. 
  749.  
  750.  2. Some program that gcc expects to be in the PATH is not; unfortunately, gcc 
  751.     crashes instead of just printing an error message.  You may have forgotten 
  752.     to install something, or your PATH may be wrong; see above.  Giving gcc the 
  753.     -v option will cause it to print each command line as it executes it; this 
  754.     will tell you which program is missing. 
  755.  
  756.  3. You are trying to get gcc to link your program for you. It cannot because 
  757.     ld does not exist, and so it crashes (see item 2).  You must specify -c, 
  758.     -E, or -S on every invokation of gcc, and then use LINK386.EXE to create an 
  759.     executable.  See the sample makefiles for an example of how to do this. 
  760.  
  761. [Colin Jensen, the current maintainer of GCC/2, also adds the following...] 
  762.  
  763. Not true as of gcc/2 2.3.3.  Gcc will invoke a small stub program called ld.exe 
  764. that in turn will invoke link386 for you.  If the command line is too long for 
  765. the ever-pathetic link386 to handle, ld will properly create a response file. 
  766.  
  767. It is easier to use gcc/2 to call link386 than to do it yourself since gcc/2 
  768. will also arrange to call a subprogram called "collect" that is required before 
  769. linking a C++ program. 
  770.  
  771. Also, gcc/2 is just plain easier to use than link386, for example: 
  772.  
  773.          gcc -o foobar.exe mydef.def foobar.cpp mylib.lib
  774.  
  775. will compile foobar.cpp, link with mylib.lib, and pass the linker definition 
  776. file mydef.def to link386 in the correct order.  Link386 demands that you know 
  777. which types of files can be put between which sets of commas on the command 
  778. line. 
  779.  
  780.  
  781. ΓòÉΓòÉΓòÉ 6.7. How do I recompile EPM (easily)? ΓòÉΓòÉΓòÉ
  782.  
  783. I have a small CMD file to automatically compile all needed macros.  It is from 
  784. Larry Margolis (IBM), one of the authros of EPM. 
  785.  
  786. You need to have at aleast minimum knowledge of EPM.  The online manual 
  787. describes most things.    Concerning the E macros (.E) the best thing to do is, to 
  788. look in the online documentation for general questions (like: What does 
  789. 'getpminfo' do?) and then look into the supplied standard E macros for detailed 
  790. reference on hwo to use the EPM functions exactly. 
  791.  
  792. Online documentation files are: EPMTECH.INF and EPMUSERS.INF 
  793.  
  794. Here is MAKEEPM.CMD: 
  795.  
  796. @echo off
  797. set EPMPATH=h:\e;h:\e\emacros;h:\e\ebookie;h:\e\lamacros;h:\e\mye;
  798. rem Command file to call ETPM and beep in case of error.  Can be given
  799. rem a list of macro files to compile; the default is to compiler all of
  800. rem the distributed .ex files.            by Larry Margolis
  801. setlocal
  802. @if .%1 == . goto all
  803. :loop
  804. etpm %1 /v || echo 'Error in %1!'
  805. @shift
  806. @if .%1 == . goto end
  807. @goto loop
  808. :all
  809. etpm EPM /v      || echo 'Error in EPM!'
  810. etpm EPMLIST /v  || echo 'Error in EPMLIST!'
  811. etpm LAMEXTRA /v || echo 'Error in LAMEXTRA!'
  812. etpm MAILLIST /v || echo 'Error in MAILLIST!'
  813. etpm EXTRA /v    || echo 'Error in EXTRA!'
  814. etpm BKEYS /v    || echo 'Error in BKEYS!'
  815. etpm E3EMUL /v   || echo 'Error in E3EMUL!'
  816. etpm BOX /v      || echo 'Error in BOX!'
  817. etpm DRAW /v     || echo 'Error in DRAW!'
  818. etpm GET /v      || echo 'Error in GET!'
  819. etpm MATHLIB /v  || echo 'Error in MATHLIB!'
  820. etpm PUT /v      || echo 'Error in PUT!'
  821. etpm HELP /v     || echo 'Error in HELP!'
  822. etpm EPMLEX /v   || echo 'Error in EPMLEX!'
  823. etpm MAKETAGS /v || echo 'Error in MAKETAGS!'
  824. :end
  825. endlocal
  826.  
  827.  
  828. ΓòÉΓòÉΓòÉ 6.8. How to I get BC++ for DOS/Windows to run? ΓòÉΓòÉΓòÉ
  829.  
  830. Open up the Settings folder for the executable, and under "DOS Settings" set 
  831. DPMI_DOS_API to ENABLED. 
  832.  
  833.  
  834. ΓòÉΓòÉΓòÉ 7. Documentation, Help ΓòÉΓòÉΓòÉ
  835.  
  836. This section covers documentation and help available for OS/2 programming. 
  837.  
  838.  
  839. ΓòÉΓòÉΓòÉ 7.1. Where can I get information on OS/2 APIs and programming? ΓòÉΓòÉΓòÉ
  840.  
  841. The IBM Programmer's Toolkit, included in Workset/2, includes a complete 
  842. on-line syscall reference. 
  843.  
  844. You can FTP the documentation for the 16-bit calls (IBM does not supply them), 
  845. such as Vio*(), Kbd*(), Mou*(), from cdrom.com as os2/2_x/program/inf16bit.zip. 
  846.  
  847. You can order the seventeen volume IBM OS/2 Technical Library (possibly at a 
  848. discount, see question 1.2) and/or order various volumes individually. 
  849.  
  850. Most of these volumes are now published by Que books also, and can be found in 
  851. many bookstores. 
  852.  
  853. All this information is also on the OS/2 Online Book Collection CD-ROM (see the 
  854. User's Edition for details), and the Professional Developer's Kit CD-ROMs have 
  855. this information as well. 
  856.  
  857.  
  858. Related Information:
  859.  
  860. What are good reference books for programming in OS/2 and PM?
  861.  
  862.  
  863. ΓòÉΓòÉΓòÉ 7.2. Where can I get sample code? ΓòÉΓòÉΓòÉ
  864.  
  865. There is a lot of sample code included in the IBM Toolkit, and four sample 
  866. programs (with source) included with C-Set++.  GNU C/C++, from cdrom.com, 
  867. includes a sample C, C++, and C++ PM program.  The OS/2 Redbooks also have some 
  868. sample code.  cdrom.com also has little bits of OS/2 and PM source code lying 
  869. around in the os2/2_x/program directory. 
  870.  
  871.  
  872. Related Information:
  873.  
  874. What are the OS/2 redbooks, and how do I get them?
  875.  
  876.  
  877. ΓòÉΓòÉΓòÉ 7.3. Are there any OS/2 programming classes or seminars? ΓòÉΓòÉΓòÉ
  878.  
  879. Yes.  Call IBM at either 1-800-3-IBM-OS2 in U.S. (or the PS/2 Help Center). 
  880. Local IBM branches frequently hold OS/2 classes and seminars. 
  881.  
  882. See os2/2_x/info/ivleague.txt on cdrom.com or the User's Edition for a list of 
  883. third-party support organizations. 
  884.  
  885. Make sure to check your local software companies.  Many of them offer OS/2 
  886. specific classes also. 
  887.  
  888.  
  889. ΓòÉΓòÉΓòÉ 7.4. What are good ref. books for programming in OS/2 and PM? ΓòÉΓòÉΓòÉ
  890.  
  891. Van Nostrand Reinhold publishes a number of books on OS/2 2.x.  Those that 
  892. relate to programming are: 
  893.  
  894. INTEGRATING APPLICATIONS WITH OS/2 2.0
  895. By William H. Zack
  896. 0-422-01234-9
  897.  
  898. CLIENT SERVER PROGRAMMING WITH OS/2 2.0, 2nd Edition
  899. By Robert Orfali and Daniel Harkey, IBM Corporation
  900. 0-422-01219-5
  901.  
  902. WRITING OS/2 2.0 DEVICE DRIVERS IN C
  903. By Steven J. Mastrianni; Foreword by John Soyring, IBM Corporation
  904. 0-442-01141-5
  905.  
  906. OS/2 2.0 PRESENTATION MANAGER GPI: A Programming Guide to Text, Graphics, And Printing
  907. By Graham C.E. Winn, IBM Corporation
  908. 0-442-00739-6
  909.  
  910. THE COBOL PRESENTATION MANAGER PROGRAMMING GUIDE
  911. By David M. Dill, Consultant
  912. 0-442-01293-4
  913.  
  914. LEARNING TO PROGRAM OS/2 2.0 PRESENTATION MANAGER BY EXAMPLE: Putting the Pieces Together
  915. By Stephen Knight, IBM Corportaion
  916. 0-442-01292-6
  917.  
  918. THE ART OF OS/2 2.1 C PROGRAMMING
  919. By Panov, Salomon, and Panov
  920. 620p, $39.95 US (suggested) includes disk with samples
  921. ISBN 0-89435-446-9
  922.  
  923. IBM has a .INF file where all IBM OS/2 related books are listed. 
  924.  
  925.  
  926. Related Information:
  927.  
  928. What are the OS/2 redbooks, and how do I get them?
  929.  
  930.  
  931. ΓòÉΓòÉΓòÉ 7.5. What are good OS/2 programming magazines? ΓòÉΓòÉΓòÉ
  932.  
  933. OS/2 Developer 
  934.  
  935. (subscription info?) 
  936.  
  937. Electronic Developers' Magazine/2 
  938.  
  939. Excellent electronic magazine for OS/2 developers.  Available somewhat monthly 
  940. from ftp-os2.cdrom.com in 2_x/program/newsltr/edmi*.zip. 
  941.  
  942. PC Magazine 
  943.  
  944. While this is not by any means a dedicated OS/2 programming magazine, it 
  945. includes several gems from Charles Petzold, most notably a nice series on font 
  946. handling. 
  947.  
  948.  
  949. ΓòÉΓòÉΓòÉ 7.6. What are the OS/2 redbooks, and how do I get them? ΓòÉΓòÉΓòÉ
  950.  
  951. (see end note for FTP information) 
  952.  
  953. IBM publishes so-called "redbooks" on many products, including OS/2 2.x.  They 
  954. seem to be a combination of power-user's guides and design information that may 
  955. be of use to both users and programmers [I haven't received my copies yet, so I 
  956. cannot say for sure.]  These are usually intended only for special IBM 
  957. customers and contain documentation that is generally unavailable anywhere 
  958. else.  You can order these books directly from IBM (see below).  All of the 
  959. following names are implicitly preceeded by "OS/2 Version 2.0." 
  960.  
  961. Volume 1: Control Program: GG24-3730, $4.15 
  962.      Technical information on Memory Management, Task Mangement, Support, 
  963.      Installation Considerations, Hardware Considerations, Boot Manager, 
  964.      National Language Considerations, Intel 386 architecture, Channel 
  965.      Architecture and SCSI.    Documents config.sys. 
  966.  
  967. Volume 2: DOS and Windows Environment, GG24-3731, $6.20 
  968.      MVDM,8086 Emulation,MVDM DOS emulation, Device Drivers, Memory Extender 
  969.      Support, Installing and Migrating Applications, Windows Applications, 
  970.      DPMI, Running DOS apps,DOS settings, VMB. 
  971.  
  972. Volume 3:  PM and Workplace Shell GG24-3732, $3.65 
  973.      Available now, but I don't know precisely what's in it. 
  974.  
  975. Volume 4: Application Development GG24-3774, $5.25 
  976.      Technical programming info (includes list in C) Overview, Object-Oriented 
  977.      Apps, PM application model, flat memory model, building PM app, Workplace 
  978.      AOAShell and System Object Model, Direct Manipulation (Drag/drop), PM 
  979.      resources, Multitasking Considerations, SAA CUA considerations, App 
  980.      Migration, Mixing 16 and 32 bit application modules, compiling and link 
  981.      editing (SOM), Adding Online Help, Problem Determination, Managing 
  982.      Development, Naming conventions. 
  983.  
  984. Volume 5: Print Subsystem, GG24-3775, $5.20 
  985.      Information on programming the print subsystem. 
  986.  
  987. The special part number GBOF-2254 is for all currently available volumes 
  988. (presently 1-5). 
  989.  
  990. ORDERING INFORMATION: 
  991.  
  992. The OS/2 2.x Redbooks are available from IBM's TeleServices customer support 
  993. number.  The number is 1-800-7654-IBM (1-800-765-4426).  You can pay by credit 
  994. card or mail in a check after calling.  The order will take about 2 weeks but 
  995. can be sped up by paying for faster shipping. 
  996.  
  997. You can also order the redbooks from your local IBM Branch Office library. 
  998. Some possibly useful phone numbers are included here. 
  999.  
  1000.     IBM Central Library, Los Angeles CA: (213) 621-6710
  1001.         P.O. Box 60737
  1002.         Los Angeles, CA 90060
  1003.     Canada: (800) 465-1234, ext 4205 ($33.52)
  1004.     UK: (0256) 478166, (#36.51, credit cards accepted)
  1005.     Australia (Victoria): 698-1234 ($46.80 A)
  1006.         IBM Australia
  1007.         The Library
  1008.         211 Sturt Street
  1009.         South Melbourne, 3205
  1010.         Att: Kate Seeley
  1011.     Denmark: 33 32 40 55 (dkk 310)
  1012.  
  1013. The redbooks are also FTP'able from cdrom.com as the os2/ibm/misc/redbk*.zip. 
  1014. The source code that accompanies the first three redbooks can FTP'able from 
  1015. cdrom.com as os2/2_x/program/rb37*.zip. 
  1016.  
  1017.  
  1018. ΓòÉΓòÉΓòÉ 7.7. How can I view the GNU C documentation? ΓòÉΓòÉΓòÉ
  1019.  
  1020. GNU C/C++ comes with documentation from the Free Software Foundation in texinfo 
  1021. (.texi) format.  This documentation is about gcc in general, and has no 
  1022. OS/2-specific information. 
  1023.  
  1024. All utilities needed to compile/view/tex the texinfo files are readily 
  1025. available for OS/2.  The GNU texinfo package, available on cdrom.com in 
  1026. os2/all/unix/gnu/gnuinfo.zip, includes makeinfo.exe for compiling texinfo, 
  1027. info.exe for viewing them, and texinfo.tex and texindex.exe for TeXing them. 
  1028.  
  1029. An ASCII text version of the gcc documentation is also available on cdrom.com, 
  1030. in the file os2/2_x/unix/gnu/gcc2_233/gcc_inf.zip. 
  1031.  
  1032. An INF hypertext version of the gcc (and related programs) documentation was 
  1033. uploaded recently to cdrom.com. 
  1034.  
  1035. emx/gcc includes its own hypertext style reader and texinfo files for all the 
  1036. GNU tools that come with it. 
  1037.  
  1038. GCC/2 includes the hypertext manuals for gcc, gas, and gnumake as well as a PM 
  1039. reader for the manuals. 
  1040.  
  1041. GNU Emacs for OS/2 reads GNU info files in their native format, with no 
  1042. conversion necessary on the user's part. 
  1043.  
  1044.  
  1045. ΓòÉΓòÉΓòÉ 7.8. Where can I get documentation on the OBJ/LIB/EXE format used by OS/2 2.x? ΓòÉΓòÉΓòÉ
  1046.  
  1047. o The .EXE format was described briefly in PC Magazine, Vol 11 No. 12 (June 30, 
  1048.   1992?); it was also described in a 1988 issue. 
  1049. o The glib source code contains a full description of the 32 bit OBJ and LIB 
  1050.   formats.  It is found at cdrom.com:/os2/2_x/unix/gnu/gcc2_233/glibs115.zip. 
  1051. o It is available in text form from cdrom.com as os2/2_x/program/lxexe.doc. 
  1052. o OMF.INF from IBM (the IBM BBS) comes highly recommended. 
  1053.  
  1054.  
  1055. ΓòÉΓòÉΓòÉ 7.9. Where can I find information on HPFS? ΓòÉΓòÉΓòÉ
  1056.  
  1057. There is a Microsoft Systems Journal article about it (64k ZIPped, so it has a 
  1058. lot of information) in ftp-os2.cdrom.com in all/info.hpfs.zip. 
  1059.  
  1060.  
  1061. ΓòÉΓòÉΓòÉ 8. PM Programming ΓòÉΓòÉΓòÉ
  1062.  
  1063. This section covers Presentation Manager programming. 
  1064.  
  1065.  
  1066. ΓòÉΓòÉΓòÉ 8.1. Printing ΓòÉΓòÉΓòÉ
  1067.  
  1068. This section covers Presentation Manager printing. 
  1069.  
  1070.  
  1071. ΓòÉΓòÉΓòÉ 8.1.1. Are there any SIMPLE examples of printing? ΓòÉΓòÉΓòÉ
  1072.  
  1073. Here is some sample code, but also check out PRINTQ12.ZIP on cdrom.com in 
  1074. 2_x/program. PRINTQ12.ZIP contains a DLL that encapselates alot of the messy 
  1075. details. 
  1076.  
  1077. Here is the working code for allowing the user to change the printer setup. 
  1078. I've also included the code that I use to start and end printing, so you can 
  1079. see how it all works. 
  1080.  
  1081. If you have any questions or comments, feel free to write. 
  1082.  
  1083. PrinterSetup() is the routine that gets the printer setup information from the 
  1084. user. 
  1085.  
  1086. GetPrinterHPS() is the routine that gets the DC and PS for the printer, and 
  1087. starts the document. 
  1088.  
  1089. EndPrint() is the routine that ends the document, and closes the DC. 
  1090.  
  1091. First, here's a little sample of how to use PrinterSetup(), GetPrinterHPS(), 
  1092. and EndPrint(): 
  1093.  
  1094. {
  1095.    HPS          hPrinterPS;
  1096.    HDC          hPrinterDC;
  1097.    DEVOPENSTRUC dops;
  1098.  
  1099.    ...
  1100.  
  1101.    dops->pszLogAddress = NULL;  // in case PrinterSetup fails, this will tell
  1102.                                 // GetPrinterHPS() to use default printer info
  1103.  
  1104.    PrinterSetup(&dops);
  1105.  
  1106.    hPrinterPS = GetPrinterHPS(&dops, &hPrinterDC,
  1107.                               "Document Name", 0L, 0L);
  1108.    if (hPrinterPS != GPI_ERROR) {
  1109.       // do your printing here
  1110.  
  1111.       EndPrint(hPrinterPS, hPrinterDC, "Document Name");
  1112.    }
  1113.  
  1114.    ...
  1115. }
  1116.  
  1117.  
  1118. /*
  1119. ******************************************************************************
  1120. **  FUNCTION: PrinterSetup
  1121. **  PURPOSE :   This function allows the user to change printer settings.
  1122. **
  1123. **  PARAMS  :   lpdos - the printer info
  1124. **  RETURN  :   BOOL   (TRUE = success)
  1125. **
  1126. **  DATE    :   11-Dec-1992
  1127. **  AUTHOR  :   Carl Samos
  1128. ******************************************************************************
  1129. **  Modified: Date:     Description of changes
  1130. **  CNS     :   11-Dec-1992 Initial version
  1131. ******************************************************************************
  1132. */
  1133. BOOL PrinterSetup(DEVOPENSTRUC FAR *lpdos)
  1134. {
  1135.    PDRIVDATA     pDriveData;      /*  The drive data  */
  1136.    unsigned long ulSize;          /*  The buffer size required  */
  1137.    char          szPrinter[32];   /*  The printer name  */
  1138.    PSZ           pszDriver;       /*  The driver name  */
  1139.    PSZ           pszLogicalPort;  /*  The logical port  */
  1140.    char          szDeviceName[32];/*  The printer's name */
  1141.  
  1142.  
  1143.    // get the printer driver, name and logical port
  1144.    // GetPrinterInformation allocates space for pszDriver and pszLogicalPort
  1145.    if (!GetPrinterInformation(szPrinter, &pszDriver,
  1146.                               szDeviceName,&pszLogicalPort))
  1147.       return(FALSE);
  1148.  
  1149.  
  1150.    // get the size needed for the DRIVDATA struct
  1151.    ulSize = DevPostDeviceModes(habMain, NULL, pszDriver, NULL, szPrinter, 0L);
  1152.  
  1153.  
  1154.    if (ulSize != DPDM_NONE && ulSize != DPDM_ERROR) {
  1155.       pDriveData = (PDRIVDATA) _fmalloc(ulSize);
  1156.       pDriveData->cb = ulSize;
  1157.  
  1158.       // bring up the dialog boxes, and fill the DRIVDATA struct
  1159.       ulSize = DevPostDeviceModes(habMain, pDriveData, pszDriver, NULL,
  1160.                                   szPrinter, 0L);
  1161.  
  1162.       if (ulSize == DEV_OK) {
  1163.           // if there is a printer name, copy it into the DRIVDATA
  1164.           if (szDeviceName[0] != '\0')
  1165.              strcpy(pDriveData->szDeviceName, szDeviceName);
  1166.  
  1167.           // remove the old information
  1168.           if (lpdos->pszLogAddress != NULL) {
  1169.              _ffree(lpdos->pszLogAddress);
  1170.           }
  1171.           if (lpdos->pszDriverName != NULL) {
  1172.              _ffree(lpdos->pszDriverName);
  1173.           }
  1174.           if (lpdos->pdriv != NULL)
  1175.              _ffree(lpdos->pdriv);
  1176.  
  1177.           /*  Setup the DEVOPENSTRUC  */
  1178.           lpdos->pszLogAddress = pszLogicalPort;
  1179.           lpdos->pszDriverName = pszDriver;
  1180.           lpdos->pszDataType   = NULL;
  1181.           lpdos->pdriv         = pDriveData;
  1182.       }
  1183.       else {
  1184.           _ffree(pszDriver);
  1185.           _ffree(pszLogicalPort);
  1186.           _ffree(pDriveData);
  1187.       }
  1188.    }
  1189.    else {
  1190.       _ffree(pszDriver);
  1191.       _ffree(pszLogicalPort);
  1192.    }
  1193.  
  1194.    return(TRUE);
  1195. }
  1196.  
  1197.  
  1198. /*
  1199. ******************************************************************************
  1200. **  FUNCTION:   GetPrinterInformation
  1201. **  PURPOSE :   This function gets the current printer information from the
  1202. **                    os2.ini file.
  1203. **
  1204. **  PARAMS  :   PSZ pszPrinter
  1205. **              PSZ pszDriver
  1206. **              PSZ pszDeviceName
  1207. **              PSZ pszLogicalPort
  1208. **
  1209. **  RETURN  :   void
  1210. **
  1211. **  DATE    :   11-Dec-1992
  1212. **  AUTHOR  :   Carl Samos
  1213. ******************************************************************************
  1214. **  Modified: Date:     Description of changes
  1215. **  CNS     :   11-Dec-1992 Initial version
  1216. ******************************************************************************
  1217. */
  1218. BOOL GetPrinterInformation(PSZ pszPrinter, PSZ FAR *lpszDriver,
  1219.                            PSZ pszDeviceName, PSZ FAR *lpszLogicalPort)
  1220. {
  1221.    int  cb;
  1222.    char szDetails[256];
  1223.    PSZ  pszBegin;
  1224.    PSZ  pszTemp;
  1225.    char szPort[64];
  1226.    char szDriver[64];
  1227.    char szLogPort[64];
  1228.  
  1229.    /*  Get the printer name  */
  1230.    cb = WinQueryProfileString(habMain, "PM_SPOOLER",
  1231.                               "PRINTER", "", pszPrinter,32);
  1232.    pszPrinter[cb-2] = 0;
  1233.  
  1234.  
  1235.    /*  Get the other details  */
  1236.    WinQueryProfileString(habMain, "PM_SPOOLER_PRINTER", pszPrinter, "",
  1237.                          szDetails, 256);
  1238.  
  1239.    // the profile string has the following format:
  1240.    // PORT;DRIVER;LOGICAL PORT;NETWORK INFO;
  1241.    // fields can have more than one entry, separated by a comma
  1242.    // the printer's name will follow the driver, separated by a period.
  1243.  
  1244.    pszBegin = szDetails;
  1245.  
  1246.    // get the printer port
  1247.    pszTemp = strchr(pszBegin, ';');
  1248.    if (pszTemp != NULL) {
  1249.       *pszTemp = '\0';
  1250.       strcpy(szPort, pszBegin);
  1251.       *pszTemp = ';';
  1252.       pszBegin = pszTemp + 1;
  1253.  
  1254.       // check for a comma in the string
  1255.       pszTemp = strchr(szPort, ',');
  1256.       if (pszTemp != NULL) *pszTemp = '\0';
  1257.    }
  1258.    else {
  1259.       return(FALSE);
  1260.    }
  1261.  
  1262.    // now get the driver and printer name
  1263.    pszTemp = strchr(pszBegin, ';');
  1264.    if (pszTemp != NULL) {
  1265.       *pszTemp = '\0';
  1266.       strcpy(szDriver, pszBegin);
  1267.       *pszTemp = ';';
  1268.       pszBegin = pszTemp + 1;
  1269.  
  1270.       // check for a period (printer name follows it)
  1271.       pszTemp = strchr(szDriver, '.');
  1272.       if (pszTemp != NULL) {
  1273.          strcpy(pszDeviceName, pszTemp+1);
  1274.          *pszTemp = '\0';
  1275.       }
  1276.       else {
  1277.          pszDeviceName[0] = '\0';
  1278.       }
  1279.  
  1280.       // check for a comma in the string
  1281.       pszTemp = strchr(szDriver, ',');
  1282.       if (pszTemp != NULL)
  1283.         *pszTemp = '\0';
  1284.    }
  1285.    else {
  1286.       return(FALSE);
  1287.    }
  1288.  
  1289.  
  1290.    // now get the logical port
  1291.    pszTemp = strchr(pszBegin, ';');
  1292.    if (pszTemp != NULL) {
  1293.       *pszTemp = '\0';
  1294.       strcpy(szLogPort, pszBegin);
  1295.       *pszTemp = ';';
  1296.       pszBegin = pszTemp + 1;
  1297.  
  1298.       // check for a comma in the string
  1299.       pszTemp = strchr(szLogPort, ',');
  1300.       if (pszTemp != NULL)
  1301.         *pszTemp = '\0';
  1302.    }
  1303.    else {
  1304.       return(FALSE);
  1305.    }
  1306.  
  1307.    *lpszDriver = _fmalloc(sizeof(char) * (strlen(szDriver)+1));
  1308.    strcpy(*lpszDriver, szDriver);
  1309.  
  1310.    *lpszLogicalPort = _fmalloc(sizeof(char) * (strlen(szLogPort)+1));
  1311.    strcpy(*lpszLogicalPort, szLogPort);
  1312.  
  1313.    return(TRUE);
  1314. }
  1315.  
  1316.  
  1317. /*
  1318. ******************************************************************************
  1319. **  FUNCTION: GetPrinterHPS
  1320. **  PURPOSE :   Gets the presentation space for a printer, and starts the doc
  1321. **  PARAMS  :   lpdos
  1322. **          :   lphDC           - the printer's hdc
  1323. **          :   pszDocName      - the name of the document
  1324. **          :   lWidth          - the width of the document
  1325. **          :   lHeight         - the height of the document
  1326. **  RETURN  : hPS
  1327. **  DATE    :   11-Dec-1992
  1328. **  AUTHOR  :   Carl Samos
  1329. ******************************************************************************
  1330. **  Modified: Date:     Description of changes
  1331. **  CNS     :   11-Dec-1992 Initial version
  1332. ******************************************************************************
  1333. */
  1334. HPS GetPrinterHPS(DEVOPENSTRUC FAR *lpdos, HDC FAR* lphDC, PSZ pszDocName,
  1335.           LONG lWidth, LONG lHeight)
  1336. {
  1337.    LONG  lReturn;
  1338.    SIZEL sizl;
  1339.    HPS   hPS;
  1340.  
  1341.    if (lpdops->pszLogAddress == NULL) {  // get the default settings
  1342.       char szPrinter[32];   /*  The printer name    */
  1343.       PSZ  pszDriver;       /*  The driver name  */
  1344.       PSZ  pszLogicalPort;  /*  The logical port    */
  1345.       char szDeviceName[32];/*  The printer's name */
  1346.  
  1347.       // GetPrinterInformation allocates space for pszDriver and pszLogicalPort
  1348.       if (!GetPrinterInformation(szPrinter, &pszDriver, szDeviceName,
  1349.                                  &pszLogicalPort))
  1350.       return(GPI_ERROR);
  1351.  
  1352.       lpdops->pszLogAddress = pszLogicalPort;
  1353.       lpdops->pszDriverName = pszDriver;
  1354.       lpdops->pszDataType   = NULL;
  1355.       lpdops->pdriv         = NULL;
  1356.    }
  1357.  
  1358.    // open the printer DC
  1359.    *lphDC = DevOpenDC (habMain, OD_QUEUED, "*", 4L, lpdops, (HDC) NULL);
  1360.    if (*lphDC == DEV_ERROR) {
  1361.       return(GPI_ERROR);
  1362.    }
  1363.  
  1364.    // start the document
  1365.    lReturn = DevEscape(*lphDC, DEVESC_STARTDOC, strlen(pszDocName),
  1366.                        pszDocName,NULL, NULL);
  1367.  
  1368.    // get the PS for the printer
  1369.    if (lReturn == DEV_OK) {
  1370.        sizl.cx = lWidth;
  1371.        sizl.cy = lHeight;
  1372.  
  1373.        if (lWidth == 0) {
  1374.           hPS =  GpiCreatePS (habMain, *lphDC, &sizl,
  1375.                               PU_LOENGLISH | GPIF_DEFAULT |
  1376.                               GPIT_NORMAL | GPIA_ASSOC);
  1377.           return(hPS);
  1378.        }
  1379.        else {
  1380.           hPS = GpiCreatePS (habMain, *lphDC, &sizl,
  1381.                               PU_ARBITRARY | PU_LOENGLISH |
  1382.                               GPIF_DEFAULT | GPIT_NORMAL |
  1383.                               GPIA_ASSOC);
  1384.           return(hPS);
  1385.       }
  1386.    }
  1387.  
  1388.    return(GPI_ERROR);
  1389. }
  1390.  
  1391.  
  1392. /*
  1393. ******************************************************************************
  1394. **  FUNCTION: EndPrint
  1395. **  PURPOSE : To close the hdc and end the document
  1396. **  PARAMS  : hpsPrinter - the printer's presentation space
  1397. **     : hdcPrinter - the printer's device context
  1398. **     : pszDocName - the name of the document
  1399. **  RETURN  : nothing
  1400. **  DATE    :   11-Dec-1992
  1401. **  AUTHOR  :   Carl Samos
  1402. ******************************************************************************
  1403. **  Modified: Date:     Description of changes
  1404. **  CNS     :   11-Dec-1992 Initial version
  1405. ******************************************************************************
  1406. */
  1407. void EndPrint(HPS hpsPrinter, HDC hdcPrinter, PSZ pszDocName)
  1408. {
  1409. DevEscape(hdcPrinter, DEVESC_ENDDOC, strlen(pszDocName),
  1410. pszDocName, NULL,NULL);
  1411. GpiAssociate(hpsPrinter, (HDC) NULL);
  1412. DevCloseDC(hdcPrinter);
  1413. GpiDestroyPS(hpsPrinter);
  1414. }
  1415.  
  1416. Credit:  Carl Samos 
  1417.  
  1418.  
  1419. ΓòÉΓòÉΓòÉ 8.1.2. Is there an easy way to get printer output (another opinion)? ΓòÉΓòÉΓòÉ
  1420.  
  1421. A reader who desires to remain anonymous writes: 
  1422.  
  1423. Generally:  My understanding was that OS/2 would handle printing for me.  That 
  1424. is to say that I wouldn't have to create separate printer drivers for every 
  1425. printer under the sun (or any for that matter).  Since I am creating an image 
  1426. on the screen that is device independent (well, mostly anyway), is there an 
  1427. easy way to get printer output? 
  1428.  
  1429. PM achieves a level of device independence by defining a logical output space. 
  1430. This logical output space is then bound to a physical output space, which 
  1431. creates a mapping of logical characteristics to their physical counterparts. 
  1432. The logical and physical output spaces are referred to as the presentation 
  1433. space and the device context (HPS and HDC) and are bound to one another by 
  1434. using either the GpiAssociate function or by specifying GPIA_ASSOC to the 
  1435. GpiCreatePS function. 
  1436.  
  1437. The easiest way to accomplish what you desire is to organize your drawing code 
  1438. into one or more functions with a single entrypoint that accepts an HPS as a 
  1439. parameter.  Then, when you want to draw to the screen, you can call 
  1440. WinGetPS/WinBeginPaint to get an HPS and call the function. When you want 
  1441. hardcopy, you call DevOpenDC to get an HDC and GpiCreatePS to get an HPS and 
  1442. call the function. 
  1443.  
  1444. Note that to get hardcopy, you need to perform some additional setup to get 
  1445. things to work properly.  The two most important things are that you initialize 
  1446. the DEVOPENSTRUC structure properly before calling DevOpenDC and that you send 
  1447. the following escape codes (via DevEscape) at the following times: 
  1448.  
  1449.   hdcPrn=DevOpenDC(...);
  1450.   hpsPrn=GpiCreatePS(...);
  1451.  
  1452.   DevEscape(...,DEVESC_STARTDOC,...);
  1453.  
  1454.   if (!doDraw(hpsPrn)) {
  1455.      DevEscape(...,DEVESC_ABORTDOC,...);
  1456.   } /* endif */
  1457.  
  1458.   DevEscape(...,DEVESC_ENDDOC,...);
  1459.  
  1460.   GpiDestroyPS(hpsPrn);
  1461.   DevCloseDC(hdcPrn);
  1462.  
  1463. I'm not sure because I can't seem to find my copy anywhere, but I belive that 
  1464. the book by Graham Winn (entitled something to the effect of "Building 
  1465. applications using the OS/2 Presentation Manager") dedicates a chapter to the 
  1466. nuances of printing. 
  1467.  
  1468. (Quoted almost directly from EDMI/2 Edition 1) 
  1469.  
  1470.  
  1471. Related Information:
  1472.  
  1473. What are good reference books for programming in OS/2 and PM?
  1474.  
  1475.  
  1476. ΓòÉΓòÉΓòÉ 8.1.3. How do I print a bitmap? ΓòÉΓòÉΓòÉ
  1477.  
  1478. Here's my code for sending a bitmap to the printer I'm leaving out the part 
  1479. where I maintain an aspect ratio between the screen and the printer page. 
  1480.  
  1481.     SIZEL sizl = {0,0};
  1482.     // Get DC/PS for printer
  1483.     hdcPrinter = GetPrinterDC( hab, PM_Q_STD );
  1484.     hpsPrinter = GpiCreatePS( hab, hdcPrinter, &sizl,
  1485.                               PU_PELS | GPIF_DEFAULT |
  1486.                               GPIT_NORMAL | GPIA_ASSOC);
  1487.  
  1488.     // Get DC/PS for memory DC compatible with printer
  1489.     hdcPrtMem = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, hdcPrinter );
  1490.     hpsPrtMem = GpiCreatePS( hab, hdcPrtMem, &sizl,
  1491.                              PU_PELS | GPIF_DEFAULT |
  1492.                              GPIT_MICRO | GPIA_ASSOC );
  1493.  
  1494.     // Get DC/PS for memory DC compatible with display
  1495.     hdcMemory = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, NULLHANDLE );
  1496.     hpsMemory = GpiCreatePS( hab, hdcMemory, &sizl,
  1497.                              PU_PELS | GPIF_DEFAULT |
  1498.                              GPIT_MICRO | GPIA_ASSOC );
  1499.  
  1500.     // Get PS for a window to be printed
  1501.     hpsToPrint = WinGetPS( hwndToPrint );
  1502.  
  1503.     // Set up memory BitBlt
  1504.     BITMAPINFOHEADER2 bmih;
  1505.     LONG alBitmapStuff[ 2 ];
  1506.     WinQueryWindowPos( hwndToPrint, &swp );
  1507.     bmih.cbFix = sizeof( BITMAPINFOHEADER2 );
  1508.     bmih.cx = swp.cx;
  1509.     bmih.cy = swp.cy;
  1510.     GpiQueryDeviceBitmapFormats( hpsToPrint, 2L, alBitmapStuff );
  1511.     bmih.cPlanes = (USHORT) alBitmapStuff[ 0 ];
  1512.     bmih.cBitCount = (USHORT) alBitmapStuff[ 1 ];
  1513.  
  1514.     // ....Set up aptl[0],[1],[2],[3] for the memory BitBlt
  1515.  
  1516.     // Do BitBlt from Display memory PS to Printer memory PS
  1517.     hbmToPrint = GpiCreateBitmap( hpsMemory, &bmih, 0, NULL, NULL );
  1518.     GpiSetBitmap( hpsMemory, hbmToPrint );
  1519.     GpiBitBlt( hpsMemory, hpsToPrint, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE );
  1520.     GpiSetBitmap( hpsMemory, NULLHANDLE );
  1521.  
  1522.     GpiSetBitmap( hpsPrtMem, hbmToPrint );
  1523.  
  1524.     // ....Set up aptl[0],[1],[2],[3] for the printer BitBlt
  1525.  
  1526.     // BitBlt to printer PS from Printer memory PS
  1527.     DevEscape( hdcPrinter, DEVESC_STARTDOC,strlen( szDocName ), szDocName,
  1528.                &lBytes, NULL );
  1529.     GpiBitBlt( hpsPrinter, hpsPrtMem, 4L, aptl, ROP_SRCCOPY,BBO_IGNORE );
  1530.     DevEscape( hdcPrinter, DEVESC_ENDDOC, 0, NULL, &lBytes, NULL );
  1531.     GpiSetBitmap( hpsPrtMem, NULLHANDLE );
  1532.     GpiDeleteBitmap( hbmToPrint );
  1533.  
  1534.     // Release all hdc's and hps's
  1535.  
  1536. Credit:  Rick Fishman 
  1537.  
  1538.  
  1539. ΓòÉΓòÉΓòÉ 8.1.4. How do I do my own Print Screen? ΓòÉΓòÉΓòÉ
  1540.  
  1541. The following code segments are drawn from a much larger system that I manage 
  1542. at work.  The intent is to show how to provide a graphical print screen 
  1543. capability in a PM program.  We install a hook to watch for the print screen 
  1544. key and then take a bit map snapshot of the screen.  This bit map is then sent 
  1545. to the printer. Forgive me if I don't go into all the details about the 
  1546. non-related data structures -- it's late and my mind is a bit foggy. 
  1547.  
  1548. Feel free to use anything here.  Please add some kind of acknowledgement, if 
  1549. you use them as is, like: 
  1550.  
  1551.   "Print routines (c) 1990, 1991 Applied Signal Technology, Inc." 
  1552.  
  1553. Comment, questions, ridicule should be directed to:
  1554.  
  1555.   Jeff Hitchcock
  1556.   CompuServe 71601,260
  1557.  
  1558.   or U.S. Mail to
  1559.  
  1560.   Applied Signal Technology, Inc.
  1561.   470 Spring Park Place, Suite 700
  1562.   Herndon, VA 22070
  1563.  
  1564.   or phone to
  1565.  
  1566.   703/478-5619
  1567.  
  1568. /*****************************************************************************/ 
  1569.  
  1570. 1.  During the WM_CREATE message processing, add the following: 
  1571.  
  1572.    // Set the print screen hook
  1573.  
  1574.    WinSetHook (hab, HMQ_CURRENT, HK_INPUT, (PFN) PrintScreenHook,
  1575.                (HMODULE) NULL);
  1576.  
  1577. /*****************************************************************************/ 
  1578.  
  1579. 2.  Somewhere, have this function: 
  1580.  
  1581. BOOL CALLBACK PrintScreenHook (HAB hab, PQMSG pQmsg, USHORT fs)
  1582. {
  1583.    if ( pQmsg->msg == WM_CHAR )
  1584.       if ( ( SHORT1FROMMP(pQmsg->mp1) & KC_KEYUP) &&
  1585.            ( SHORT1FROMMP(pQmsg->mp1) & KC_VIRTUALKEY ) &&
  1586.            ( SHORT2FROMMP(pQmsg->mp2) == VK_PRINTSCRN) )
  1587.              PrintScreen (hab);
  1588.    return FALSE;
  1589. }
  1590.  
  1591. /*****************************************************************************/ 
  1592.  
  1593. 3.  Here's the "driver:" 
  1594.  
  1595. VOID EXPENTRY PrintScreen (HAB hab)
  1596. {
  1597.     HBITMAP     hbm;
  1598.  
  1599.     hbm = ScreenToBitmap (hab);
  1600.     PrintBitMap(hbm);
  1601. }
  1602.  
  1603. /*****************************************************************************/ 
  1604.  
  1605. 4.  Here's a general print-related structure we use.  We often have many print 
  1606. threads running concurrently, but we only allow one to "run" at a time.  We use 
  1607. a semaphore to show availability of the printer (so to speak), and only one 
  1608. thread at a time gets it.    If we didn't do this, and more than a few print 
  1609. threads are running (especially graphical prints), even a 486/33 with 16 MB of 
  1610. RAM begins to C-R-A-W-L.  So, for what it's worth, these are the structures 
  1611. that we use: 
  1612.  
  1613. /**************************************************************
  1614. *                                                             *
  1615. *   PRINTTHREADPARAMS structure                               *
  1616. *                                                             *
  1617. *   Parameters that are used to manage separate print threads *
  1618. *                                                             *
  1619. *   Item             Contents/Use                             *
  1620. *   --------------   ---------------------------------------- *
  1621. *                                                             *
  1622. *   sJobNumber       Print job number, used for cancelling    *
  1623. *   aiThreadStack    Thread's stack                           *
  1624. *   hwndNotify       Window to which notif. msgs are sent     *
  1625. *   tidPrint         System task id                           *
  1626. *   hssmPrinter...   Semaphore for printer available          *
  1627. *   fSemSet          TRUE if semaphore was made and cleared   *
  1628. *   szSummary        Print summary (e.g., fax printout)       *
  1629. *   fStart           Can't start until TRUE (default FALSE)   *
  1630. *   fContinue        Quit if FALSE (default is TRUE)          *
  1631. *   fHold            Hold if TRUE (default is FALSE)          *
  1632. *   sStartingPage    For multipage, start here                *
  1633. *   sEndingPage      For multipage, end here                  *
  1634. *   usParam          Module-dependent USHORT                  *
  1635. *   ulParam          Module-dependent ULONG                   *
  1636. *   pPrintData       PVOID to the print data                  *
  1637. *                                                             *
  1638. *   PAGESETUP structure                                       *
  1639. *                                                             *
  1640. *   Parameters used to describe the appearance                *
  1641. *                                                             *
  1642. *   Item             Contents/Use                             *
  1643. *   --------------   ---------------------------------------- *
  1644. *                                                             *
  1645. *   szFont           The name of the font to use              *
  1646. *   sLinesPerPage    Used to scale font                       *
  1647. *   sCharsPerLine    Used to scale font                       *
  1648. *   sLeft            Used to position on page, in chars       *
  1649. *   sRight           Used to position on page, in char        *
  1650. *   sTop             Used to position on page, in lines       *
  1651. *   sBottom          Used to position on page, in lines       *
  1652. *   szHeader         Text to place on top of each page        *
  1653. *   fIncludeSummary  If TRUE, include SRI summary on page 1   *
  1654. *   fHeaderEveryPage TRUE for every page, false for pg 1      *
  1655. *   fHeaderUnderline TRUE for underline                       *
  1656. *   szFooter         Text to place at bottom of each page     *
  1657. *   fFooterEveryPage TRUE for every page, false for pg 1      *
  1658. *   fOverlineFooter  TRUE for overline                        *
  1659. *                                                             *
  1660. *   HEADER AND FOOTER OPTIONS:                                *
  1661. *                                                             *
  1662. *   Special Flags that should be supported in each module:    *
  1663. *                                                             *
  1664. *           &l  Left justify                                  *
  1665. *           &c  Center                                        *
  1666. *           &r  Right justify                                 *
  1667. *           &d  Date                                          *
  1668. *           &t  Time                                          *
  1669. *           &p  Page number                                   *
  1670. *                                                            *
  1671. **************************************************************/
  1672.  
  1673. typedef struct
  1674.     {
  1675.     CHAR       szFont[FACESIZE] ;
  1676.     SHORT      sLinesPerPage ;
  1677.     SHORT      sCharsPerLine ;
  1678.     SHORT      sLeft ;
  1679.     SHORT      sRight ;
  1680.     SHORT      sTop ;
  1681.     SHORT      sBottom ;
  1682.     BOOL       fIncludeSummary ;
  1683.     CHAR       szHeader[HEADERFOOTERLENGTH] ;
  1684.     BOOL       fHeaderEveryPage ;
  1685.     BOOL       fUnderlineHeader ;
  1686.     CHAR       szFooter[HEADERFOOTERLENGTH] ;
  1687.     BOOL       fFooterEveryPage ;
  1688.     BOOL       fOverlineFooter ;
  1689.     }
  1690.     PAGESETUP ;
  1691.  
  1692. typedef PAGESETUP FAR *PPAGESETUP ;
  1693.  
  1694. typedef struct
  1695.     {
  1696.     SHORT        sJobNumber ;
  1697.     int          aiThreadStack[STACKSIZE / sizeof (int)] ;
  1698.     HWND         hwndNotify ;
  1699.     HSYSSEM      hssmPrinterAvailable ;
  1700.     BOOL         fSemSet ;
  1701.     CHAR         szSummary[HEADERFOOTERLENGTH] ;
  1702.     BOOL         fStart ;
  1703.     BOOL         fRunning ;
  1704.     BOOL         fContinue ;
  1705.     BOOL         fHold ;
  1706.     SHORT        sStartingPage ;
  1707.     SHORT        sEndingPage ;
  1708.     PAGESETUP    page ;
  1709.     USHORT       usParam ;
  1710.     ULONG        ulParam ;
  1711.     VOID huge    *pPrintData ;
  1712.     }
  1713.     PRINTTHREADPARAMS ;
  1714.  
  1715. typedef PRINTTHREADPARAMS FAR *PPRINTTHREADPARAMS ;
  1716.  
  1717. /*****************************************************************************/ 
  1718.  
  1719. 5.  This function saves the screen display to a bitmap. 
  1720.  
  1721. HBITMAP ScreenToBitmap (HAB hab)
  1722. {
  1723.      BITMAPINFOHEADER bmp ;
  1724.      HBITMAP          hbm ;
  1725.      HDC              hdcMemory ;
  1726.      HPS              hpsScreen, hpsMemory ;
  1727.      LONG             alBitmapFormats [2] ;
  1728.      POINTL           aptl[3] ;
  1729.      SIZEL            sizl ;
  1730.      SHORT            cxScreen;
  1731.      SHORT            cyScreen;
  1732.      BOOL             fMonochrome = FALSE;
  1733.                       // Create memory DC and PS
  1734.  
  1735.      cxScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  1736.      cyScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  1737.  
  1738.      hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ;
  1739.  
  1740.      sizl.cx = sizl.cy = 0 ;
  1741.      hpsMemory = GpiCreatePS (hab, hdcMemory, &sizl,
  1742.                               PU_PELS | GPIF_DEFAULT |
  1743.                               GPIT_MICRO | GPIA_ASSOC) ;
  1744.  
  1745.                               // Create bitmap for destination
  1746.  
  1747.      bmp.cbFix = sizeof bmp ;
  1748.  
  1749.      if (fMonochrome)
  1750.      {
  1751.         bmp.cPlanes = 1 ;
  1752.         bmp.cBitCount = 1 ;
  1753.      }
  1754.      else
  1755.      {
  1756.         GpiQueryDeviceBitmapFormats (hpsMemory, 2L, alBitmapFormats) ;
  1757.  
  1758.         bmp.cPlanes = (USHORT) alBitmapFormats[0] ;
  1759.         bmp.cBitCount = (USHORT) alBitmapFormats[1] ;
  1760.      }
  1761.  
  1762.      bmp.cx = cxScreen ;
  1763.      bmp.cy = cyScreen ;
  1764.  
  1765.      hbm = GpiCreateBitmap (hpsMemory, &bmp, 0L, NULL, NULL) ;
  1766.  
  1767.                               // Copy from screen to bitmap
  1768.  
  1769.      if (hbm != NULL)
  1770.      {
  1771.         GpiSetBitmap (hpsMemory, hbm) ;
  1772.         hpsScreen = WinGetScreenPS (HWND_DESKTOP) ;
  1773.  
  1774.         aptl[0].x = 0 ;
  1775.         aptl[0].y = 0 ;
  1776.         aptl[1].x = cxScreen ;
  1777.         aptl[1].y = cyScreen ;
  1778.         aptl[2].x = 0 ;
  1779.         aptl[2].y = 0 ;
  1780.  
  1781.         WinLockVisRegions (HWND_DESKTOP, TRUE) ;
  1782.  
  1783.         GpiBitBlt (hpsMemory, hpsScreen, 3L, aptl,
  1784.                    fMonochrome ? ROP_NOTSRCCOPY : ROP_SRCCOPY, BBO_IGNORE) ;
  1785.  
  1786.         WinLockVisRegions (HWND_DESKTOP, FALSE) ;
  1787.  
  1788.         WinReleasePS (hpsScreen) ;
  1789.         GpiDestroyPS (hpsMemory) ;
  1790.         DevCloseDC (hdcMemory) ;
  1791.      }
  1792.  
  1793.      return hbm ;
  1794. }
  1795.  
  1796. /***************************************************************************** 
  1797.  
  1798. 6.  The "core" function: 
  1799.  
  1800. This function prints a bitmap to the printer.  The bitmap is scaled according 
  1801. to the size of the printer.  No distortion is allowed of the bitmap image. 
  1802.  
  1803. Returns False : if an error occurrs 
  1804. Returns True : no Error occurred 
  1805.  
  1806. Known bug(s): 
  1807.  
  1808. Areas on the screen that have a black foreground and a gray background are 
  1809. completely black when printed.  For example, when a window does not have the 
  1810. focus, it's title bar becomes black lettering on a gray background.  When this 
  1811. window is printed, the entire title bar is black and no title can be read. 
  1812. This is using the Hewlett Packard LaserJet Series II printer. 
  1813.  
  1814. According to MicroSoft online help this is a known bug with the printer device 
  1815. driver.    To fix the bug you must go to the control panel and change the colors 
  1816. of the inactive window. 
  1817.  
  1818. ************************************************************************/
  1819. SHORT  sBitmapToPrinter(PPRINTTHREADPARAMS pptp,
  1820. HPS   hpsPrinter,
  1821. HDC   hdcPrinter,
  1822. HAB   habPrinter,
  1823. SIZEL *psizlPage,
  1824. SIZEL *psizlChar)
  1825. {
  1826.     HDC    hdcPrinterMemory;
  1827.     HPS    hpsPrinterMemory;
  1828.     POINTL ptl;
  1829.     SHORT  sPage = 1;
  1830.     RECTL  rcl;     // Coordinates of region
  1831.  
  1832.     long  lCapsHRes;
  1833.     long  lCapsVRes;
  1834.     float fYAspectRatio;
  1835.     float fXAspectRatio;
  1836.     SIZEL sizl;
  1837.  
  1838.     HBITMAP hbm;
  1839.     POINTL  aptl [4] ;
  1840.     SHORT   cxScreen;
  1841.     SHORT   cyScreen;
  1842.     float   fltScale;
  1843.  
  1844.     // Skip down top margin, ...
  1845.  
  1846.     ptl.x = pptp->page.sLeft * psizlChar->cx ;
  1847.     ptl.y = psizlPage->cy - (pptp->page.sTop * psizlChar->cy) ;
  1848.  
  1849.     // Print header, if requested
  1850.  
  1851.     if (pptp->page.szHeader[0] != '\0')
  1852.     {
  1853.        PrintHeaderFooter (hpsPrinter, &ptl, pptp,
  1854.                           psizlPage, psizlChar,
  1855.                           pptp->page.szHeader,
  1856.                           sPage, PRINT_HEADER) ;
  1857.     }
  1858.  
  1859.     hbm = pptp->pPrintData;
  1860.  
  1861.     // Find the aspect ratio of the printer
  1862.  
  1863.     DevQueryCaps(hdcPrinter,CAPS_HORIZONTAL_RESOLUTION,1L,&lCapsHRes);
  1864.     DevQueryCaps(hdcPrinter,CAPS_VERTICAL_RESOLUTION,1L,&lCapsVRes);
  1865.  
  1866.     if ( (lCapsVRes == 0) || (lCapsHRes == 0) ) {
  1867.        fXAspectRatio = (float) 1;
  1868.        fYAspectRatio = (float) 1;
  1869.     }
  1870.     else {
  1871.        fXAspectRatio = (float) ((float) lCapsVRes / (float) lCapsHRes);
  1872.        fYAspectRatio = (float) ((float) lCapsHRes / (float) lCapsVRes);
  1873.     }
  1874.  
  1875.     // determine coordinates to print on printer
  1876.  
  1877.     rcl.xLeft =  pptp->page.sLeft * psizlChar->cx; // Printer left
  1878.  
  1879.     rcl.xRight = psizlPage->cx -
  1880.                  (pptp->page.sRight * psizlChar->cx); // Printer right
  1881.  
  1882.     rcl.yBottom = (pptp->page.sBottom + 1) * psizlChar->cy; // Printer bottom
  1883.  
  1884.     rcl.yTop = psizlPage->cy -
  1885.               ( (pptp->page.sTop + 1) * psizlChar->cy);     // Printer top
  1886.  
  1887.     cxScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  1888.     cyScreen = (SHORT) WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  1889.  
  1890.     ScaleToWindowSize ((SHORT) (rcl.xRight - rcl.xLeft),   // sXtarget
  1891.                        (SHORT) (rcl.yTop - rcl.yBottom),   // sYTarget
  1892.                        cxScreen,                           // sXSource
  1893.                        cyScreen,                           // sYSource
  1894.                        &fltScale) ;
  1895.  
  1896.     // Create a memory device context
  1897.     // Memory device contexts are used to contain bitmaps
  1898.  
  1899.     hdcPrinterMemory = DevOpenDC (habPrinter, OD_MEMORY, "*", 0L,
  1900.                                   NULL, hdcPrinter);
  1901.  
  1902.     if ( hdcPrinterMemory == DEV_ERROR ) return FALSE;
  1903.  
  1904.     sizl.cx = 0;
  1905.     sizl.cy = 0;
  1906.  
  1907.     // Create a presentation space and associate it the memory device context
  1908.  
  1909.     hpsPrinterMemory = GpiCreatePS (habPrinter, hdcPrinterMemory, &sizl,
  1910.                                     PU_PELS | GPIF_DEFAULT |
  1911.                                     GPIT_NORMAL | GPIA_ASSOC);
  1912.  
  1913.     if( ! hpsPrinterMemory) {
  1914.        DevCloseDC (hdcPrinterMemory);
  1915.        return FALSE;
  1916.     }
  1917.  
  1918.     GpiSetBitmap(hpsPrinterMemory,hbm);
  1919.  
  1920.     aptl [0].x = rcl.xRight - (long) ((float) cxScreen * fltScale);
  1921.     aptl [0].y = rcl.yTop - (long) ((float) cyScreen * fltScale *
  1922.                  fYAspectRatio);
  1923.     aptl [1].x = rcl.xRight;
  1924.     aptl [1].y = rcl.yTop;
  1925.     aptl [2].x = 0;
  1926.     aptl [2].y = 0;
  1927.     aptl [3].x = cxScreen;
  1928.     aptl [3].y = cyScreen;
  1929.  
  1930.     GpiBitBlt(hpsPrinter,hpsPrinterMemory,4L,aptl,ROP_SRCCOPY,BBO_IGNORE);
  1931.  
  1932.     GpiAssociate   (hpsPrinterMemory, NULL) ;
  1933.     GpiDestroyPS   (hpsPrinterMemory);
  1934.     DevCloseDC     (hdcPrinterMemory);
  1935.  
  1936.     // If a footer is defined, ...
  1937.  
  1938.     if (pptp->page.szFooter[0] != '\0')
  1939.     {
  1940.        // ... compute its position ...
  1941.  
  1942.        ptl.x = pptp->page.sLeft * psizlChar->cx ;
  1943.        ptl.y = pptp->page.sBottom * psizlChar->cy ;
  1944.  
  1945.        // ... and print it.
  1946.  
  1947.        PrintHeaderFooter (hpsPrinter, &ptl, pptp,
  1948.                           psizlPage, psizlChar,
  1949.                           pptp->page.szFooter,
  1950.                          sPage, PRINT_FOOTER) ;
  1951.    }
  1952.    return( TRUE);
  1953. }
  1954.  
  1955.  
  1956. ΓòÉΓòÉΓòÉ 8.2. Menus ΓòÉΓòÉΓòÉ
  1957.  
  1958. This section covers Presentation Manager menus. 
  1959.  
  1960.  
  1961. ΓòÉΓòÉΓòÉ 8.2.1. How do I add a menu to a dialog box? ΓòÉΓòÉΓòÉ
  1962.  
  1963. Do a WinLoadMenu and then WM_UPDATEFRAME. 
  1964.  
  1965.  
  1966. ΓòÉΓòÉΓòÉ 8.2.2. How do I make a dynamically changing menu? ΓòÉΓòÉΓòÉ
  1967.  
  1968. Create the menu with all the items that it will ever contain, then dynamically 
  1969. remove and insert the items as required. After loading menu, Query and maintain 
  1970. a copy of the menuitem(s) that will be removed. 
  1971.  
  1972.  // Obtain and keep a copy of the convert submenuitem
  1973.   if (!WinSendMsg (pwd->hwndAB, MM_QUERYITEM,
  1974.       MPFROM2SHORT (IDM_KanCnvMnu, TRUE), MPFROMP (&pwd->miCnvMnu))) {
  1975.  
  1976.   // And the convert submenu text
  1977.   if (!WinSendMsg (pwd->hwndAB, MM_QUERYITEMTEXT,
  1978.     MPFROM2SHORT (IDM_KanCnvMnu, sizeof (pwd->szCnvMnuTxt)),
  1979.                   MPFROMP (&pwd->szCnvMnuTxt)) ){
  1980.  
  1981. When menu is to updated, insert/remove as necessary 
  1982.  
  1983.     // This is layout, is the submenu already in place?
  1984.     if (!pwd->fCnvMenu) {
  1985.  
  1986.       // The submenu is not installed, so insert the submenu
  1987.       WinSendMsg (pwd->hwndAction, MM_INSERTITEM,
  1988.                   MPFROMP (&pwd->miCnvMnu), MPFROMP (pwd->szCnvMnuTxt));
  1989.  
  1990.       // And remove the convert menuitem
  1991.       WinSendMsg (pwd->hwndAB, MM_REMOVEITEM,
  1992.                   MPFROM2SHORT (IDM_KanCnv, TRUE), 0L);
  1993.  
  1994.       // Set the submenu flag
  1995.       pwd->fCnvMenu = TRUE;
  1996.     }
  1997.  
  1998. Credit:  Matthew S. Osborn 
  1999.  
  2000.  
  2001. ΓòÉΓòÉΓòÉ 8.2.3. How do I create a conditional cascade menu? ΓòÉΓòÉΓòÉ
  2002.  
  2003. The following works for me to set a submenu as a conditional-cascade menu, then 
  2004. set it's default id (hwndMenu is the hwnd of the top-level menu): 
  2005.  
  2006.    MENUITEM mi;
  2007.  
  2008.    WinSendMsg( hwndMenu, MM_QUERYITEM,
  2009.                MPFROM2SHORT( idSubMenu, TRUE ), &mi );
  2010.  
  2011.    // Set the MS_CONDITIONALCASCADE bit for the submenu.
  2012.  
  2013.    WinSetWindowBits( mi.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE,
  2014.                      MS_CONDITIONALCASCADE );
  2015.  
  2016.    // Set cascade menu default
  2017.  
  2018.    WinSendMsg( mi.hwndSubMenu, MM_SETDEFAULTITEMID,
  2019.                MPFROMSHORT( idDefaultItem ), NULL );
  2020.  
  2021. Then I do this to query the default item: 
  2022.  
  2023.  MENUITEM mi;
  2024.  
  2025.  WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT( idSubMenu, TRUE ),
  2026.              &mi );
  2027.  
  2028.  id = (USHORT) WinSendMsg( mi.hwndSubMenu,
  2029.                            MM_QUERYDEFAULTITEMID, NULL, NULL );
  2030.  
  2031. Credit:  Rick Fishman 
  2032.  
  2033.  
  2034. ΓòÉΓòÉΓòÉ 8.2.4. How do I remove a separator from a menu? ΓòÉΓòÉΓòÉ
  2035.  
  2036. Here are two methods of doing that.  The first is from the PMHINTS file, and 
  2037. the second is from Gpf.  PMHINTS takes the approach of removing SC_CLOSE and 
  2038. the nearby separator.  The Gpf solution takes the approach of deleting 
  2039. everything that it doesn't explicitly want.  I've extended it to, among other 
  2040. things, conditionally delete the "Window List" menu item as well. 
  2041.  
  2042. The deletion problems get messier in application menus when there are multiple 
  2043. separaters in different pull-downs.  That is when assigning the separators an 
  2044. id really pays off. 
  2045.  
  2046. Both examples are 16-bit OS/2 1.x code. 
  2047.  
  2048. PMHINTS: 
  2049.  
  2050.  VOID  DelClose(HWND hwnd)
  2051.  {
  2052.    HWND        hSysMenu,
  2053.                hSysSubMenu;
  2054.    MENUITEM    SysMenu;
  2055.    SHORT       idItem,
  2056.                idSep,
  2057.                idSysMenu;
  2058.  
  2059.    hSysMenu = WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT, FALSE),
  2060.                               FID_SYSMENU);
  2061.  
  2062.    idSysMenu = SHORT1FROMMR(WinSendMsg(hSysMenu, MM_ITEMIDFROMPOSITION,
  2063.                             NULL, NULL));
  2064.  
  2065.    WinSendMsg(hSysMenu, MM_QUERYITEM, MPFROM2SHORT(idSysMenu, FALSE),
  2066.               MPFROMP(&SysMenu));
  2067.  
  2068.    hSysSubMenu = SysMenu.hwndSubMenu;
  2069.  
  2070.    idItem = SHORT1FROMMR(WinSendMsg(hSysSubMenu, MM_ITEMPOSITIONFROMID,
  2071.                          MPFROM2SHORT(SC_CLOSE, FALSE), NULL));
  2072.    if (idItem != MIT_ERROR)
  2073.    {
  2074.      idSep = idItem + 1;  // Get separator ID
  2075.  
  2076.      idSep  = SHORT1FROMMR(WinSendMsg(hSysSubMenu, MM_ITEMIDFROMPOSITION,
  2077.                            MPFROMSHORT(idSep), NULL));
  2078.  
  2079.      WinSendMsg(hSysMenu, MM_DELETEITEM, MPFROM2SHORT(SC_CLOSE, TRUE),
  2080.                 MPFROMSHORT(NULL));
  2081.  
  2082.      WinSendMsg(hSysSubMenu, MM_DELETEITEM, MPFROM2SHORT(idSep, FALSE), NULL);
  2083.    }
  2084.  }
  2085.  
  2086. Derived from Gpf, adapted for a client, with some of my changes expurgated (so 
  2087. it won't compile as is): 
  2088.  
  2089.  /*****
  2090.   *
  2091.   *  UtilDlgSysMenu
  2092.   *
  2093.   *      Remove unavailable items from system menu of dialog box.
  2094.   *
  2095.   *  History:
  2096.   *      8/31/92  gts  Adapted from Gpf's GpfSetDialogBoxSysMenu
  2097.   *               with slight modifications.
  2098.   *
  2099.   *****/
  2100.  
  2101.  void _export UtilDlgSysMenu (          /* Remove unwanted system menu items */
  2102.  HWND hwndFrame)                      /* I - Handle to dialog window */
  2103.  {
  2104.     HWND     hwndSubMenu;             /* sys menu pull-down handle  */
  2105.     MENUITEM miTemp;                  /* menu item template         */
  2106.     SHORT    sItemId;                 /* system menu item ID        */
  2107.     SHORT    sItemIndex;              /* system menu item index     */
  2108.     MRESULT  mresult;
  2109.  
  2110.     /********************************************************************/
  2111.     /* Get the handle of the system menu pull-down.            */
  2112.     /********************************************************************/
  2113.     hwndSubMenu = WinWindowFromID( hwndFrame, FID_SYSMENU );
  2114.     WinSendMsg( hwndSubMenu,
  2115.                 MM_QUERYITEM,
  2116.                 MPFROM2SHORT( SC_SYSMENU, FALSE ),
  2117.                 MPFROMP( (PSZ)&miTemp ) );
  2118.     hwndSubMenu = miTemp.hwndSubMenu;
  2119.  
  2120.     /********************************************************************/
  2121.     /* Remove all items from the system menu pull-down that are no    */
  2122.     /* longer wanted.                            */
  2123.     /********************************************************************/
  2124.     mresult = WinSendMsg( hwndSubMenu,
  2125.                          MM_QUERYITEMCOUNT,
  2126.                          MPFROMSHORT(0),
  2127.                          MPFROMSHORT(0) );
  2128.     sItemIndex = SHORT1FROMMR(mresult);
  2129.     for (sItemId = 0; sItemIndex != -1; sItemIndex--)
  2130.     {
  2131.        mresult = WinSendMsg( hwndSubMenu,
  2132.                              MM_ITEMIDFROMPOSITION,
  2133.                              MPFROMSHORT(sItemIndex),
  2134.                              MPFROMSHORT(0) );
  2135.        sItemId = SHORT1FROMMR(mresult);
  2136.        if ( sItemId != MIT_ERROR
  2137.              &&sItemId != SC_MOVE
  2138.              &&sItemId != SC_CLOSE
  2139.              &&(sItemId != SC_TASKMANAGER
  2140.              || (flFlags & MAXONLY)) )   // <- application controls
  2141.        {
  2142.           WinSendMsg( hwndSubMenu,
  2143.                       MM_DELETEITEM,
  2144.                       MPFROM2SHORT(sItemId,FALSE),
  2145.                       MPFROMSHORT(0) );
  2146.        }
  2147.     }
  2148.  }
  2149.  
  2150. Credit:  Guy Scharf 
  2151.  
  2152.  
  2153. ΓòÉΓòÉΓòÉ 8.3. Container Controls ΓòÉΓòÉΓòÉ
  2154.  
  2155. This section covers Presentation Manager container controls. 
  2156.  
  2157.  
  2158. ΓòÉΓòÉΓòÉ 8.3.1. How do I stop a container from flashing every time I add a record? ΓòÉΓòÉΓòÉ
  2159.  
  2160. Disable/Enable the container window before and after the insertion/deletion. 
  2161.  
  2162.  
  2163. ΓòÉΓòÉΓòÉ 8.3.2. How do I get my containers to use Mini-icons? ΓòÉΓòÉΓòÉ
  2164.  
  2165. Here is some sample code that displays mini icons.  First, supply a missing 
  2166. #define: 
  2167.  
  2168.  #ifndef CCS_MINIICONS
  2169.      #define CCS_MINIICONS 0x0800
  2170.  #endif // not CCS_MINIICONS
  2171.  
  2172. Use CCS_MINIICONS as part of your container style (when you create the 
  2173. container).  Now, fill in the RECORDCORE structure pointed to by 'pRecordCore'; 
  2174. 'pUserRecord' also points to 'pRecordCore', which is part of a "user data" 
  2175. structure: 
  2176.  
  2177.  // Fill in fields of container record.
  2178.  #ifdef USE_MINIRECORDCORE
  2179.      pRecordCore->cb = sizeof (MINIRECORDCORE) ;
  2180.  #else
  2181.      pRecordCore->cb = sizeof (RECORDCORE) ;
  2182.  #endif // USE_MINIRECORDCORE
  2183.      pRecordCore->flRecordAttr = 0 ; // CRA_DROPONABLE ;
  2184.      // pRecordCore->ptlIcon is left to zeros.
  2185.      pRecordCore->pszIcon = pUserRecord->szName ;
  2186.      if (*DDirRecord.szIconName)
  2187.         LoadIcon (pUserRecord) ;
  2188.      // pRecordCore->hptrMiniIcon is left to zeros.
  2189.      // pRecordCore->hbmBitmap is left to zeros.
  2190.      // pRecordCore->hbmMiniBitmap is left to zeros.
  2191.      // pRecordCore->pTreeItemDesc is left to zeros.
  2192.  
  2193.  #ifndef USE_MINIRECORDCORE
  2194.      pRecordCore->pszText = pUserRecord->szName ;
  2195.      pRecordCore->pszName = pUserRecord->szName ;
  2196.      pRecordCore->pszTree = pUserRecord->szName ;
  2197.  #endif // not USE_MINIRECORDCORE
  2198.  
  2199. Now, if your user asks for mini-icons (via a popup menu, presumably), you send 
  2200. a CM_SETCNRINFO message to your container, after ORing in the CV_MINI style to 
  2201. CnrInfo.flWindowAttr, or removing it to restore full-size icons.  Hope this 
  2202. helps. 
  2203.  
  2204. Credit:  Wayne Kovsky 
  2205.  
  2206.  
  2207. ΓòÉΓòÉΓòÉ 8.3.3. How do I sort a container control? ΓòÉΓòÉΓòÉ
  2208.  
  2209. /*
  2210.  * Note that PSESSION is my own instance data structure.
  2211.  * I use it here to retrieve the type of field comparison I should do.
  2212.  */
  2213.  
  2214.  static SHORT APIENTRY Compare (PMINIRECORDCORE pmrc1,
  2215.                                 PMINIRECORDCORE pmrc2,
  2216.                                 PVOID pvStorage)
  2217.  {
  2218.     PSESSION pSession = (PSESSION) pvStorage ;
  2219.     PFIELDINFO pFieldInfo = pSession->pFieldInfoSort ;
  2220.     PPVOID pField1 = (PPVOID) ((PBYTE) pmrc1 +
  2221.        pFieldInfo->offStruct) ;
  2222.     PPVOID pField2 = (PPVOID) ((PBYTE) pmrc2 +
  2223.        pFieldInfo->offStruct) ;
  2224.     SHORT sResult = 0 ;
  2225.  
  2226.     if (pFieldInfo->flData & CFA_STRING) {
  2227.        sResult = strcmp ((PCHAR) *pField1, (PCHAR) *pField2) ;
  2228.     }
  2229.     else if (pFieldInfo->flData & CFA_ULONG) {
  2230.        if ((ULONG) *pField1 < (ULONG) *pField2)
  2231.           sResult = -1 ;
  2232.        else if ((ULONG) *pField1 > (ULONG) *pField2)
  2233.           sResult = 1 ;
  2234.        else
  2235.           sResult = 0 ;
  2236.     }
  2237.     else if (pFieldInfo->flData & CFA_DATE) {
  2238.        sResult = CompareDate ((PCDATE) (PVOID) pField1,
  2239.                               (PCDATE) (PVOID) pField2) ;
  2240.     }
  2241.     else if (pFieldInfo->flData & CFA_TIME) {
  2242.        sResult = CompareTime ((PCTIME) (PVOID) pField1,
  2243.                               (PCTIME) (PVOID) pField2) ;
  2244.     }
  2245.  
  2246.     // Any other data type gets treated as equal;
  2247.     // no sorting can be done. Now handle reverse sequence.
  2248.     if (pSession->fSortReverse && sResult)
  2249.        sResult = -sResult ;
  2250.     return sResult ;
  2251.  }
  2252.  
  2253. Here is how I invoke the sort: 
  2254.  
  2255.  // Send container a sort message.
  2256.  ulRC = LONGFROMMR (WinSendMsg (
  2257.                     pSession->hwndContainer,
  2258.                     CM_SORTRECORD,
  2259.                     MPFROMP (Compare), MPFROMP (pSession))) ;
  2260.  if (!ulRC) {
  2261.     // Report error.
  2262.  }
  2263.  
  2264. Credit:  Wayne Kovsky 
  2265.  
  2266.  
  2267. ΓòÉΓòÉΓòÉ 8.3.4. How do I query all records in a container - tree view? ΓòÉΓòÉΓòÉ
  2268.  
  2269. The following code works for querying all records in a tree structure but 
  2270.  
  2271.  USHORT usParentCmd = CMA_FIRST, usChildCmd;
  2272.  PUSERREC purParent = NULL, purChild;
  2273.  
  2274.  for( ; ; )
  2275.  {
  2276.     purParent = (PUSERREC) WinSendMsg( hwndCnr, CM_QUERYRECORD,
  2277.                                        MPFROMP( purParent ),
  2278.                                        MPFROM2SHORT( usParentCmd, CMA_ITEMORDER ) );
  2279.     if( !purParent )
  2280.        break;
  2281.  
  2282.     DoWhatever( purParent );
  2283.  
  2284.     usChildCmd = CMA_FIRSTCHILD;
  2285.     purChild = NULL;
  2286.     for( ; ; )
  2287.     {
  2288.        purChild = (PUSERREC) WinSendMsg( hwndCnr, CM_QUERYRECORD,
  2289.                                          MPFROMP( purChild ),
  2290.                                          MPFROM2SHORT( usChildCmd, CMA_ITEMORDER ));
  2291.        if( !purChild )
  2292.           break;
  2293.  
  2294.        DoWhatever( purChild );
  2295.        usChildCmd = CMA_NEXT;
  2296.     }
  2297.  
  2298.     usCmdParent = CMA_NEXT;
  2299.  }
  2300.  
  2301. Credit:  Rick Fishman 
  2302.  
  2303.  
  2304. ΓòÉΓòÉΓòÉ 8.4. I can't get different colors in text control windows ΓòÉΓòÉΓòÉ
  2305.  
  2306. I've finally got static text control windows (WS_STATIC, SS_TEXT) working with 
  2307. a different color pres. parameter set ! Thanks, Rick, Dan and Wayne. Code as 
  2308. follows: 
  2309.  
  2310.  RGB2 rgb2 ;   // RGB2 structure
  2311.  HWND hwnd ;   // window handle
  2312.  
  2313.  // Set RGB values for a SYSCLR_BACKGROUND (light gray) color
  2314.  rgb2.bred = 204 ;     // Found these in 'WinSetSysColors' API
  2315.  rgb2.bgreen = 204 ;
  2316.  rgb2.bblue = 204 ;
  2317.  rgb2.fcOptions = 0 ;
  2318.  // Set background color
  2319.  WinSetPresParam (hwnd, PP_BACKGROUNDCOLOR, (ULONG) sizeof (RGB2),
  2320.                   &rgb2) ;
  2321.  // Set RGB values for black
  2322.  rgb2.bred = 0 ;
  2323.  rgb2.bgreen = 0 ;
  2324.  rgb2.bblue = 0 ;
  2325.  rgb2.fcOptions = 0 ;
  2326.  // Set text foreground color
  2327.  WinSetPresParam (hwnd, PP_FOREGROUNDCOLOR, (ULONG) sizeof (RGB2),
  2328.                   &rgb2) ;
  2329.  // Set text border color (important for outline fonts)
  2330.  WinSetPresParam (hwnd, PP_BORDERCOLOR, (ULONG) sizeof (RGB2), &rgb2) ;
  2331.  
  2332. Three big caveats here: 
  2333.  
  2334.  1. The OS/2 internal code for static text control windows is *definitely* 
  2335.     using RGB colors, not index colors when it draws the text string. Thus, the 
  2336.     PP_*INDEX presentation parameter values will *not* work. 
  2337.  2. You *must* use a set of colors that are already loaded in the color table. 
  2338.     If the RGB color is not found, the background will be dithered affecting 
  2339.     the text appearance (washed out). If you are not sure the RGB color is 
  2340.     loaded do a GpiQueryNearestColor to get the nearest color. 
  2341.  3. You *must* use the RGB2 structure and *not* the RGB structure. This is 
  2342.     *NOT* documented, but it appears in general that all OS/2 2.0 APIs should 
  2343.     use RGB2 *instead* of RGB. 
  2344.  
  2345. Credit:  Bill Kenning 
  2346.  
  2347.  
  2348. ΓòÉΓòÉΓòÉ 8.5. How can I toggle my titlebar on and off? ΓòÉΓòÉΓòÉ
  2349.  
  2350. Basically, move frame window controls from being children of the frame to being 
  2351. children of the background HWND_OBJECT.  You can then reverse the process to 
  2352. bring them back into view.  Following function implements this code. 
  2353.  
  2354. /* --------------------------------------------------------------
  2355. -- Function:  ToggleFrame
  2356. --
  2357. -- Description:  Toggles frame control visible/invisible
  2358. --
  2359. -- Notes: Code stolen from someone who stole it from an MS sample
  2360. ----------------------------------------------------------------- */
  2361. void ToggleFrame(HWND hwndFrame) {
  2362.  
  2363.  if (! Hidden) {     /* hide contorls */
  2364.     hwndTitle = WinWindowFromID( hwndFrame, FID_TITLEBAR );
  2365.     hwndSys   = WinWindowFromID( hwndFrame, FID_SYSMENU );
  2366.         ... repeat for FID_MINMAX, etc ...
  2367.     WinSetParent(hwndTitle, HWND_OBJECT, FALSE );
  2368.     WinSetParent(hwndSys,   HWND_OBJECT, FALSE );
  2369.         ... repeat for FID_MINMAX, etc ...
  2370.  }
  2371.  else { /* restore controls */
  2372.     WinSetParent( hwndTitle, hwndFrame, FALSE );
  2373.     WinSetParent( hwndSys, hwndFrame, FALSE );
  2374.         ... basically reverse of above ...
  2375.  }
  2376.  WinSendMsg( hwndFrame, WM_UPDATEFRAME,
  2377.       (MPARAM)(FCF_TITLEBAR | FCF_SYSMENU | ...), NULL);
  2378.  SizeTheWindow( hwndFrame );
  2379.  Hidden = ! Hidden;
  2380.  return;
  2381. }
  2382.  
  2383. Credit:  Mike Thompson 
  2384.  
  2385.  
  2386. ΓòÉΓòÉΓòÉ 8.6. How can I get transparent regions in bitmaps? ΓòÉΓòÉΓòÉ
  2387.  
  2388. Currently, you can get the same effect with PM if you use the method used with 
  2389. icons: 
  2390.  
  2391.  1. Use a monochrome mask to prep the destination area. The mask would define 
  2392.     which areas would be transparent and which would show the bitmap. The bits 
  2393.     would be defined as 1=transparent,0=bitmap. You would blit the mask to the 
  2394.     destination using ROP_SRCAND. This would blacken out the area that would 
  2395.     display the non-transparent bits of the bitmap. 
  2396.  2. Now blit the bitmap to the destination using ROP_SRCPAINT. Note that the 
  2397.     "transparent" areas of the bitmap must have the color black (i.e. bits=0). 
  2398.     This ORs the bitmap onto the prep area. Viola - "transparent" bitmap. 
  2399.  
  2400. Credit:  John Webb 
  2401.  
  2402.  
  2403. ΓòÉΓòÉΓòÉ 8.7. How do I create a status bar at the bottom of my window? ΓòÉΓòÉΓòÉ
  2404.  
  2405. You need to intercept several frame messages: 
  2406.  
  2407. WM_CALCFRAMERECT to calculate the new location of the client.  You should send 
  2408. it to the frame superclass then modify the result.  This message is invoked 
  2409. during frame formatting and whenever WinCalcFrameRect is called against your 
  2410. frame window handle. 
  2411.  
  2412. WM_FRAMECTLCOUNT to tell the frame superclass the number of frame controls you 
  2413. expect to format.  If you're adding a status line as a child of the frame 
  2414. (below the client, I suspect), you would add 1 to the result returned by your 
  2415. frame superclass. 
  2416.  
  2417. WM_FORMATFRAME is where you actually position/size the frame controls. The 
  2418. message gives you an array of SWP's.  Call your frame superclass and modify the 
  2419. result (in your case, I would expect only FID_CLIENT and your status line). 
  2420.  
  2421. Sample follows... 
  2422.  
  2423.     /*
  2424.      * FYI, WinDefFrameProc is just a macro I defined to
  2425.      * call my superclass frame window procedure, ie,
  2426.      *    (*vpfnFrameWndProc) (h,m,p1,p2).
  2427.      *
  2428.      * This example splits the client area space 1/3
  2429.      * and 2/3 horizontally with the old client area
  2430.      * and a new sibling.
  2431.      */
  2432.  
  2433.     case WM_CALCFRAMERECT:
  2434.       mr = WinDefFrameProc(hwnd, msg, mp1, mp2);
  2435.  
  2436.       /*
  2437.        * Calculate the position of the client rectangle
  2438.        * Otherwise,  we'll see a lot of redraw when we move the
  2439.        * client during WM_FORMATFRAME.
  2440.        */
  2441.  
  2442.       if (mr && mp2)
  2443.       {
  2444.          prectl = (PRECTL) mp1;
  2445.          prectl->xLeft += ((prectl->xRight - prectl->xLeft) / 3);
  2446.       }
  2447.       break;
  2448.  
  2449.     case WM_FORMATFRAME:
  2450.       sCount = (SHORT) WinDefFrameProc(hwnd, msg, mp1, mp2);
  2451.  
  2452.       /*
  2453.        * Reformat the frame to move the client
  2454.        * over and make room for the his/her sibling.
  2455.        */
  2456.  
  2457.       pswp = (PSWP) mp1;
  2458.       pswpClient = pswp + sCount - 1;
  2459.       pswpNew = pswpClient + 1;
  2460.  
  2461.       *pswpNew = *pswpClient;
  2462.       swpClient = *pswpClient;
  2463.  
  2464.       pswpNew->hwnd = WinWindowFromID(hwnd, ID_SIBLING);
  2465.       pswpNew->cx = pswpClient->cx / 3;
  2466.  
  2467.       pswpClient->x = pswpNew->x + pswpNew->cx - 1;
  2468.       pswpClient->cx = swpClient.cx - pswpNew->cx + 1;
  2469.  
  2470.       sCount++;
  2471.       mr = MRFROMSHORT(sCount);
  2472.       break;
  2473.  
  2474.     case WM_QUERYFRAMECTLCOUNT:
  2475.       sCount = (SHORT) WinDefFrameProc(hwnd, msg, mp1, mp2);
  2476.       sCount++;
  2477.       mr = MRFROMSHORT(sCount);
  2478.       break;
  2479.  
  2480. Credit:  Dan Kehn 
  2481.  
  2482.  
  2483. ΓòÉΓòÉΓòÉ 8.8. How to have a frame/client and still have a std window? ΓòÉΓòÉΓòÉ
  2484.  
  2485.  FRAMECDATA fcdata;
  2486.  
  2487.  fcdata.cb          = sizeof( FRAMECDATA );
  2488.  fcdata.flCreateFlags = FCF_TASKLIST | FCF_MENU, etc.;
  2489.  fcdata.hmodResources = 0; // or the hmod of the DLL containing the resources
  2490.  fcdata.idResources   = ID_RESOURCES;  // ID of the resources, as usual
  2491.  
  2492.  hwndFrame = WinCreateWindow( HWND_DESKTOP, WC_FRAME, NULL, 0, 0, 0, 0, 0,
  2493.                               NULLHANDLE, HWND_TOP, ID_RESOURCES,
  2494.                               &fcdata, NULL);
  2495.  
  2496.  hwndClient = WinCreateWindow( hwndFrame, szClientClass, NULL, 0, 0, 0, 0, 0,
  2497.                                NULLHANDLE, HWND_TOP, FID_CLIENT, NULL, NULL );
  2498.  
  2499.  WinSetWindowPos( hwndFrame, HWND_TOP, x, y, cx, cy,
  2500.                   SWP_ZORDER | SWP_SIZE | SWP_MOVE |
  2501.                   SWP_SHOW | SWP_ACTIVATE );
  2502.  
  2503. If you want to then add new controls, like the system menu, you would do this: 
  2504.  
  2505.  fcdata.flCreateFlags = FCF_SYSMENU;
  2506.  WinCreateFrameControls( hwndFrame, &fcdata, NULL );
  2507.  WinSendMsg( hwndFrame, WM_UPDATEFRAME,
  2508.              MPFROMLONG( FCF_SYSMENU ), NULL );
  2509.  
  2510. The same thing applies to all the other controls like FCF_SIZEBORDER, 
  2511. FCF_TITLEBAR, FCF_HORZSCROLL, FCF_MINMAX, etc. You could also OR more than one 
  2512. together if you wanted to add more than one frame control in the same shot. On 
  2513. the titlebar, you need to also send this message: 
  2514.  
  2515.  WinSendMsg( WinWindowFromID( hwndFrame, FID_TITLEBAR ),
  2516.              TBM_SETHILITE, MPFROMSHORT( TRUE ), NULL );
  2517.  
  2518. If you want to delete frame controls, you would do this (assuming system menu): 
  2519.  
  2520.  WinDestroyWindow( WinWindowFromID( hwndFrame, FID_SYSMENU ) );
  2521.  WinSendMsg( hwndFrame, WM_UPDATEFRAME,
  2522.              MPFROMLONG( FCF_SYSMENU ), NULL );
  2523.  
  2524. Unfortunately this doesn't fit completely well with OOP, since the controls 
  2525. really are not themselves objects independent of the frame window. One of the 
  2526. problems here is that in order to make them independent objects, you need to 
  2527. know the internals of the frame window proc. For instance, you would think that 
  2528. the MIN and MAX are two WC_BUTTON controls, but they are really one menu with 
  2529. two bitmap menuitems (at least in 1.x they were). So if you were to do a 
  2530. WinCreateWindow for either, you'd have to know where to get the bitmaps, and 
  2531. hope that doesn't change. 
  2532.  
  2533. Similarly you'd have to be able to construct the system menu after creating a 
  2534. WC_MENU window. This isn't a tough feat, but if a later version of OS/2 adds a 
  2535. new menu item to the system menu, you'd have to become aware of it. 
  2536.  
  2537. The titlebar and the scrollbars aren't a problem since they have their own 
  2538. public window classes - WC_TITLEBAR and WC_SCROLLBAR respectively. You can, for 
  2539. instance, do a WinCreateWindow( ..., WC_SCROLLBAR,..., FID_HORZSCROLL, ..), 
  2540. then send the frame a WM_UPDATEFRAME message for FCF_HORZSCROLL and this would 
  2541. work. But there is no WC_SIZEBORDER so you couldn't use this method to add the 
  2542. sizing border later. So for the sizing border you need to use the method I 
  2543. first posted above. 
  2544.  
  2545. I spoke too soon about the sizing border. If you want to add or remove it from 
  2546. a frame window, you need to add or remove the FS_SIZEBORDER style from the 
  2547. frame, then send the frame an UPDATEFRAME message for FCF_SIZEBORDER. 
  2548.  
  2549. To change the style, here is a technique that John Webb just turned me on to. 
  2550. To add the style: 
  2551.  
  2552.  WinSetWindowBits( hwndFrame, QWL_STYLE, FS_SIZEBORDER, FS_SIZEBORDER );
  2553.  
  2554. To remove it: 
  2555.  
  2556.  WinSetWindowBits( hwndFrame QWL_STYLE, 0, FS_SIZEBORDER );
  2557.  
  2558. Also, if you want to add or remove just one of the MIN or the MAX, you 
  2559. basically need to get the window handle of the MINMAX menu, then do a 
  2560. MM_REMOVEITEM for the one you want to remove. I did this in 1.x but haven't yet 
  2561. in 2.0. 
  2562.  
  2563. Credit:  Rick Fishman 
  2564.  
  2565.  
  2566. ΓòÉΓòÉΓòÉ 8.9. How do I use printf() in a PM program? ΓòÉΓòÉΓòÉ
  2567.  
  2568. Use PMPRINTF, check your local BBS's, CIS, BIX or cdrom.com or redirect stdout 
  2569. and stderr to files. 
  2570.  
  2571.     // Redirect 'stderr'.
  2572.     (void) freopen ("stderr.txt", "w", stderr) ;
  2573.  
  2574.     // Redirect 'stdout'.
  2575.     (void) freopen ("stdout.txt", "w", stdout) ;
  2576.  
  2577.  
  2578. ΓòÉΓòÉΓòÉ 8.10. I have a SOM DLL. How do I register it? ΓòÉΓòÉΓòÉ
  2579.  
  2580. Here's an example I use for registering.  It checks if the DLL is valid before 
  2581. continuing: 
  2582.  
  2583. #define INCL_WPCLASS
  2584. #define INCL_WIN
  2585. #define INCL_DOS
  2586. #include <os2.h>
  2587. #include <string.h>
  2588. #include <stdio.h>
  2589.  
  2590. int main(int argc, char *argv[]) {
  2591.    HMQ hmq;
  2592.    HAB hab;
  2593.    CHAR szText[256];
  2594.    USHORT usResponse;
  2595.    CHAR szLoadError[128];
  2596.    HMODULE hmod;
  2597.    APIRET rc;
  2598.  
  2599.    if (argc != 3)
  2600.      return 0;
  2601.  
  2602.    hab = WinInitialize(0);
  2603.    hmq = WinCreateMsgQueue(hab, 0);
  2604.  
  2605.    WinDeregisterObjectClass(argv[1]);
  2606.  
  2607.    sprintf(szText, "Register %s DLL '%s'?", argv[1], argv[2]);
  2608.    usResponse = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szText,
  2609.       "Register WPS Class", 0, MB_YESNO | MB_MOVEABLE | MB_ICONQUESTION);
  2610.  
  2611.    if (usResponse != MBID_YES)
  2612.      return 0;
  2613.  
  2614.    rc = DosLoadModule(szLoadError, sizeof(szLoadError), argv[2], &hmod);
  2615.  
  2616.    if (rc != 0)
  2617.    {
  2618.      sprintf(szText, "Return code = %u, error module = '%s'.",
  2619.              rc, szLoadError);
  2620.      WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szText,
  2621.                    "DosLoadModule Failed", 0,
  2622.                    MB_ENTER | MB_MOVEABLE | MB_ERROR);
  2623.  
  2624.      return 0;
  2625.   }
  2626.  
  2627.  
  2628.   if (WinRegisterObjectClass(argv[1], argv[2]))
  2629.   {
  2630.     if (WinCreateObject(argv[1], argv[1], " ",
  2631.         "<WP_DESKTOP>", CO_REPLACEIFEXISTS))
  2632.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Created.",argv[1],
  2633.                     0, MB_ENTER | MB_MOVEABLE | MB_INFORMATION);
  2634.     else
  2635.     {
  2636.       DosFreeModule(hmod);
  2637.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Failed.",argv[1],
  2638.                     0,MB_ENTER | MB_MOVEABLE | MB_ERROR);
  2639.     }
  2640.   }
  2641.   else
  2642.   {
  2643.     DosFreeModule(hmod);
  2644.     WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Registration failed.",
  2645.                   argv[1], 0,MB_ENTER | MB_MOVEABLE | MB_ERROR);
  2646.   }
  2647.  
  2648.   return 0; }
  2649.  
  2650. FYI, when WPS registers your DLL with SOM, SOM checks if your DLL has a module 
  2651. entry point called SOMInitModule.  If it does, it is called (most use 
  2652. SOMInitModule for registering DLLs that have more than one class). Otherwise, 
  2653. it checks for YourClassNewClass, and tries to call it (where 'YourClass' is the 
  2654. parameter you specified on the WinRegisterObjectClass). SOM generates 
  2655. 'YourClassNewClass' in the .IH file; if you're still stuck, verify it is being 
  2656. called and that it doesn't fail (eg, because of version number check). 
  2657.  
  2658. I suggest registering with a full DLL filespec, eg, C:\MYSTUFF\MYCAR.DLL. Saves 
  2659. on the length of the LIBPATH. 
  2660.  
  2661. Credit:  Dan Kehn 
  2662.  
  2663.  
  2664. ΓòÉΓòÉΓòÉ 8.11. How do I save and restore my window size and position? ΓòÉΓòÉΓòÉ
  2665.  
  2666. Here is code I use to restore a saved window position, which includes checks to 
  2667. make sure the user hasn't saved a window position at one screen resolution and 
  2668. then restored it at a different screen resolution (which might cause the 
  2669. window's frame controls to be completely off the display -- we've all seen 
  2670. that, right???): 
  2671.  
  2672.  BOOL SetWindowPosition (const HAB hab, const HWND hwndFrame,
  2673.                          const SWP swpConfig)
  2674.  {
  2675.      SWP swp ;
  2676.      APIRET ulRC ;
  2677.  
  2678.      // Initialize the window positioning flags.
  2679.      swp.fl = SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW ;
  2680.  
  2681.      /* Check for saved user preferences for screen width/height in
  2682.       * config file.  Did user want to start maximized?
  2683.       */
  2684.      if (swpConfig.fl & SWP_MAXIMIZE)
  2685.      {
  2686.          // Get maximized frame window position and size.
  2687.          ulRC = WinGetMaxPosition (hwndFrame, &swp) ;
  2688.          if (!ulRC)
  2689.          {
  2690.              // Report error, and then ...
  2691.              return TRUE ;
  2692.          }
  2693.          swp.fl |= SWP_MAXIMIZE ;
  2694.      }
  2695.  
  2696.      // Did user want to start minimized?
  2697.      else if (swpConfig.fl & SWP_MINIMIZE)
  2698.      {
  2699.          // Get minimized frame window position and size.
  2700.          ulRC = WinGetMinPosition (hwndFrame, &swp, (PPOINTL) NULL) ;
  2701.          if (!ulRC)
  2702.          {
  2703.              // Report error, and then ...
  2704.              return TRUE ;
  2705.          }
  2706.          swp.fl |= SWP_MINIMIZE ;
  2707.      }
  2708.  
  2709.      // Did user have a saved starting position and size?
  2710.      else if (swpConfig.cy || swpConfig.cx || swpConfig.x || swpConfig.y)
  2711.      {
  2712.          LONG cxClientMax ;
  2713.          LONG cyClientMax ;
  2714.          LONG cyTitleBar ;
  2715.          LONG cxSizeBorder ;
  2716.          LONG cySizeBorder ;
  2717.  
  2718.          // Get maximum client window size.
  2719.          cxClientMax = WinQuerySysValue (HWND_DESKTOP, SV_CXFULLSCREEN) ;
  2720.          cyClientMax = WinQuerySysValue (HWND_DESKTOP, SV_CYFULLSCREEN) ;
  2721.          cyTitleBar = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR) ;
  2722.          cxSizeBorder = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER) ;
  2723.          cySizeBorder = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER) ;
  2724.  
  2725.          // Maximum client window size excludes title bar.
  2726.          cyClientMax += cyTitleBar ;
  2727.  
  2728.          // Make sure x origin is within display boundaries.
  2729.          swp.x = swpConfig.x ;
  2730.          if (swp.x < -cxSizeBorder)
  2731.              swp.x = 0 ;
  2732.  
  2733.          // Make sure window isn't too wide, or negative value.
  2734.          swp.cx = swpConfig.cx ;
  2735.          if (swp.cx >= cxClientMax || swp.cx < 0)
  2736.          {
  2737.              swp.cx = cxClientMax ;
  2738.              swp.x = 0 ;
  2739.          }
  2740.  
  2741.           if ((swp.x + swp.cx) > (cxClientMax + cxSizeBorder))
  2742.              swp.x = cxClientMax + cxSizeBorder - swp.cx ;
  2743.  
  2744.          // Make sure y origin is within display boundaries.
  2745.          swp.y = swpConfig.y ;
  2746.          if (swp.y < -cySizeBorder)
  2747.              swp.y = 0 ;
  2748.  
  2749.          // Make sure window isn't too high, or negative value.
  2750.          swp.cy = swpConfig.cy ;
  2751.          if (swp.cy > cyClientMax || swp.cy < 0)
  2752.          {
  2753.              swp.cy = cyClientMax ;
  2754.              swp.y = 0 ;
  2755.          }
  2756.  
  2757.          if ((swp.y + swp.cy) > (cyClientMax + cySizeBorder))
  2758.              swp.y = cyClientMax + cySizeBorder - swp.cy ;
  2759.      }
  2760.  
  2761.      // No saved position -- move window to FCF_SHELLPOSITION location.
  2762.      else
  2763.      {
  2764.          // Get default window size and position.
  2765.          ulRC = WinQueryTaskSizePos (hab, 0, &swp) ;
  2766.          if (ulRC)
  2767.          {
  2768.              // Report error, and then ...
  2769.              return TRUE ;
  2770.          }
  2771.          swp.fl = SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW ;
  2772.      }
  2773.  
  2774.      // Position and size this frame window.
  2775.      ulRC = WinSetWindowPos (hwndFrame, HWND_TOP,
  2776.        swp.x, swp.y, swp.cx, swp.cy, swp.fl) ;
  2777.      if (!ulRC)
  2778.      {
  2779.          // Report error, and then ...
  2780.          return TRUE ;
  2781.      }
  2782.  
  2783.      return FALSE ;
  2784.  }
  2785.  
  2786. Credit:  Wayne Kovsky 
  2787.  
  2788.  
  2789. ΓòÉΓòÉΓòÉ 8.12. How do you make a window float above all others? ΓòÉΓòÉΓòÉ
  2790.  
  2791. OK.  Here's a sample program showing floating windows (derived from dvipm). 
  2792. The advantages over the WM_TIMER approach [which was presented in v2.2 -ed] 
  2793. are: 
  2794.  
  2795. o there's no delay 
  2796. o repainting is minimized 
  2797. o avoids timing problems 
  2798. o the floating windows are not unconditionally moved to the very top (that is, 
  2799.   when moving the base window B (with floating window F) behind a window W, the 
  2800.   order of the windows is this: BFW, not BWF!) 
  2801.  
  2802. The excessive repainting caused by other solutions was quite annoying with 
  2803. dvipm as recomputing the dvipm status window is slow. 
  2804.  
  2805. Eberhard 
  2806.  
  2807. /* floatwin.c */
  2808.  
  2809. /* This program shows how to implement floating windows.  The source
  2810.    code works with both 16-bit and 32-bit C compilers.
  2811.  
  2812.    If the Z-order of the base window is changed, the floating window
  2813.    will be moved on top of the base window.
  2814.  
  2815.    Generalizing this approach to many windows floating on many windows
  2816.    (floating on many windows ...) is left as exercise. */
  2817.  
  2818. #define INCL_WIN
  2819. #define INCL_GPI
  2820. #include <os2.h>
  2821.  
  2822. /* Syntactic sugar for supporting both 16-bit and 32-bit compilers. */
  2823.  
  2824. #ifdef __32BIT__
  2825. #define MSG ULONG
  2826. #define FLAGS fl
  2827. #else
  2828. #define MSG USHORT
  2829. #define FLAGS fs
  2830. #endif
  2831. #ifndef NULLHANDLE
  2832. #define NULLHANDLE NULL
  2833. #endif
  2834.  
  2835. /* The original frame window procedure. */
  2836. static PFNWP pfOldBaseFrameProc = NULL;
  2837.  
  2838. /* The handle of the floating window. */
  2839. static HWND hwndFloat = NULLHANDLE;
  2840.  
  2841. /* This frame window procedure is used for subclassing base windows.
  2842.    When changing the Z-order of the frame window, the floating window
  2843.    is moved instead of the base window and the hwndInsertBehind field
  2844.    is modified to move the base window behind the floating window. */
  2845.  
  2846. MRESULT EXPENTRY
  2847. BaseFrameProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2)
  2848. {
  2849.   PSWP pswp;
  2850.  
  2851.   switch (msg)
  2852.     {
  2853.     case WM_ADJUSTWINDOWPOS:
  2854.       pswp = PVOIDFROMMP (mp1);
  2855.       if ((pswp->FLAGS & SWP_ZORDER) && hwndFloat != NULLHANDLE
  2856.            && WinIsWindowVisible (hwndFloat))
  2857.         {
  2858.           WinSetWindowPos (hwndFloat, pswp->hwndInsertBehind,
  2859.                            0, 0, 0, 0, SWP_ZORDER);
  2860.           /* This is the trick! */
  2861.           pswp->hwndInsertBehind = hwndFloat;
  2862.         }
  2863.       break;
  2864.     }
  2865.   return pfOldBaseFrameProc (hwnd, msg, mp1, mp2);
  2866. }
  2867.  
  2868.  
  2869. /* Common client window procedure for base windows and floating
  2870.    windows.  Display TXT and use CLR for filling the background. */
  2871.  
  2872. MRESULT CommonClientWndProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2,
  2873.                              PCH txt, COLOR clr)
  2874. {
  2875.   HPS hps;
  2876.   RECTL rcl;
  2877.  
  2878.   switch (msg)
  2879.     {
  2880.     case WM_PAINT:
  2881.       hps = WinBeginPaint (hwnd, 0L, 0L);
  2882.       WinQueryWindowRect (hwnd, &rcl);
  2883.       GpiSetColor (hps, CLR_DARKCYAN);
  2884.       GpiSetBackColor (hps, clr);
  2885.       WinDrawText (hps, -1, txt, &rcl, 0, 0,
  2886.                    DT_TEXTATTRS | DT_CENTER | DT_VCENTER | DT_ERASERECT);
  2887.       WinEndPaint (hps);
  2888.       return 0;
  2889.     }
  2890.   return WinDefWindowProc (hwnd, msg, mp1, mp2);
  2891. }
  2892.  
  2893.  
  2894. /* Client window procedure for floating windows. */
  2895.  
  2896. MRESULT EXPENTRY FloatClientWndProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2)
  2897. {
  2898.   return CommonClientWndProc (hwnd, msg, mp1, mp2, "Floating Window", CLR_RED);
  2899. }
  2900.  
  2901. /* Client window procedure for base windows. */
  2902.  
  2903. MRESULT EXPENTRY BaseClientWndProc (HWND hwnd, MSG msg, MPARAM mp1, MPARAM mp2)
  2904. {
  2905.   return CommonClientWndProc (hwnd, msg, mp1, mp2, "Base Window", CLR_YELLOW);
  2906. }
  2907.  
  2908.  
  2909. /* Start here. */
  2910.  
  2911. int main (void)
  2912. {
  2913.   static char szBaseClientClass[] = "floatwin.base";
  2914.   static char szFloatClientClass[] = "floatwin.float";
  2915.   ULONG flFrameFlags;
  2916.   HAB hab;
  2917.   HMQ hmq;
  2918.   QMSG qmsg;
  2919.   HWND hwndBase;
  2920.  
  2921.   /* Initialize Presentation Manager. */
  2922.  
  2923.   hab = WinInitialize (0);
  2924.   hmq = WinCreateMsgQueue (hab, 0);
  2925.  
  2926.   /* Create client window classes. */
  2927.  
  2928.   WinRegisterClass (hab, szBaseClientClass, BaseClientWndProc,
  2929.                     CS_SIZEREDRAW, 0);
  2930.   WinRegisterClass (hab, szFloatClientClass, FloatClientWndProc,
  2931.                     CS_SIZEREDRAW, 0);
  2932.  
  2933.   /* Create the base window and the floating window.  Note: the
  2934.      windows are initially invisible. */
  2935.  
  2936.   flFrameFlags = (FCF_TITLEBAR      | FCF_SYSMENU |
  2937.                   FCF_SIZEBORDER    | FCF_MINMAX  |
  2938.                   FCF_TASKLIST);
  2939.  
  2940.   /* Create and subclass the base window. */
  2941.  
  2942.   hwndBase = WinCreateStdWindow (HWND_DESKTOP, 0,
  2943.                                  &flFrameFlags, szBaseClientClass,
  2944.                                  "floatwin - Base Window",
  2945.                                  0L, 0, 1, NULL);
  2946.   pfOldBaseFrameProc = WinSubclassWindow (hwndBase, BaseFrameProc);
  2947.  
  2948.   /* Create the floating window. */
  2949.  
  2950.   hwndFloat = WinCreateStdWindow (HWND_DESKTOP, 0,
  2951.                                   &flFrameFlags, szFloatClientClass,
  2952.                                   "floatwin - Floating Window",
  2953.                                   0L, 0, 1, NULL);
  2954.  
  2955.   /* Set the position, size and Z-order of the windows and make them
  2956.      visible.  It's important to use SWP_ZORDER for the base
  2957.      window. */
  2958.  
  2959.   WinSetWindowPos (hwndFloat, HWND_TOP, 10, 10, 300, 80,
  2960.                    SWP_SHOW | SWP_MOVE | SWP_SIZE | SWP_ZORDER);
  2961.   WinSetWindowPos (hwndBase, HWND_TOP, 100, 50, 300, 80,
  2962.                    SWP_SHOW | SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_ACTIVATE);
  2963.  
  2964.   /* The message loop. */
  2965.  
  2966.   while (WinGetMsg (hab, &qmsg, 0L, 0, 0))
  2967.     WinDispatchMsg (hab, &qmsg);
  2968.  
  2969.   /* Clean up. */
  2970.  
  2971.   WinDestroyWindow (hwndBase);
  2972.   WinDestroyWindow (hwndFloat);
  2973.   WinDestroyMsgQueue (hmq);
  2974.   WinTerminate (hab);
  2975.  
  2976.   return 0;
  2977. }
  2978.  
  2979.  
  2980. ΓòÉΓòÉΓòÉ 8.13. How to ensure the sizing's correct so the dlg "fits" in the notebook...? ΓòÉΓòÉΓòÉ
  2981.  
  2982. Override wpclsQuerySettingsPageSize (or some such verbage, I don't have docs at 
  2983. home).  I don't know if this API made it into the on-line docs, but it is 
  2984. definitely public (see \TOOLKT20\C\OS2H\WPOBJECT.H). There you are given the 
  2985. opportunity to adjust the size up to accomodate your dialog, if necessary. 
  2986.  
  2987. The PAGEINFO structure is used by the Settings page code to delay the loading 
  2988. of the dialog required for a page until the user turns to it for the first 
  2989. time.  It has the resource ID, module handle (which is incorrectly named in the 
  2990. structure, 'resid' or some nonsense, grr-r), dialog procedure, and pointer of 
  2991. your choice to receive on WM_INITDLG (most choose the object pointer, somSelf). 
  2992. When the user selects the notebook tab, WPS calls WinLoadDlg based on the 
  2993. parameters in PAGEINFO. 
  2994.  
  2995.  
  2996. ΓòÉΓòÉΓòÉ 8.14. How do I prevent Shutdown from stopping my app? ΓòÉΓòÉΓòÉ
  2997.  
  2998. In our application, the WM_CLOSE message processor determines the state of the 
  2999. application, issues all the "Are you sure?" questions, etc. If the close is to 
  3000. be continued, a WM_QUIT message is posted and a value of FALSE is returned. 
  3001. Otherwise a value of TRUE is returned. 
  3002.  
  3003. The window receiving the WMU_EndTask message handles it by posting a WM_CLOSE 
  3004. message to itself, and letting the WM_CLOSE processing handle it. The only 
  3005. reason it is not translated to a WM_CLOSE within the message loop is allow 
  3006. future use. This message requires no special handling. 
  3007.  
  3008. The window receiving the WMU_ShutDown message handles it by sending (not 
  3009. posting) a WM_CLOSE message to itself. If the WM_CLOSE message returns TRUE, 
  3010. then a WinCancelShutdown (hmq, FALSE) call is issued to cancel this instance of 
  3011. the shutdown. 
  3012.  
  3013. If you issue a WinCancelShutdown (hmq, TRUE), a WM_QUIT message will never be 
  3014. sent to your message queue, so will not have an opportunity to stop the 
  3015. shutdown.  This is intended for secondary message queues that do not have a 
  3016. message loop. 
  3017.  
  3018.   while (1) {
  3019.  
  3020.     HWND hwndClient;
  3021.  
  3022.     // Get next message from queue
  3023.     if (!WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0)) {
  3024.  
  3025.       // The WM_QUIT message has three sources:
  3026.       //   1. The task manager 'End task' pulldown
  3027.       //   2. System shutdown from desktop manager
  3028.       //   3. Posted by the application
  3029.  
  3030.       // This is a WM_QUIT message.  Check the window handle, if the
  3031.       // handle matches mp2, it is from switch list close
  3032.       if (qmsg.hwnd == HWNDFROMMP (qmsg.mp2)) {
  3033.  
  3034.         // This is from close on the task list, convert to our message
  3035.         qmsg.msg = WMU_EndTask;
  3036.  
  3037.         // Get the intended client's window handle
  3038.         if (!(hwndClient = WinWindowFromID (qmsg.hwnd, FID_CLIENT))) {
  3039.  
  3040.           // Failed to find client. No idea who this belongs to,
  3041.           // give it to default window for processing
  3042.           hwndClient = hwndDefault
  3043.         }
  3044.  
  3045.         // Otherwise, readdress the message to the appropriate client
  3046.         qmsg.hwnd = hwndClient;
  3047.  
  3048.         // We can use mp1 and mp2 for anything we want.
  3049.         // Currently, just clear both
  3050.         qmsg.mp1  = qmsg.mp2 = 0L;
  3051.  
  3052.       } else if (qmsg.hwnd == NULLHANDLE) {
  3053.  
  3054.         // This message is from shutdown,
  3055.         // Address it to default window for processing
  3056.         qmsg.hwnd = hwndDefault;
  3057.  
  3058.         // And set the message to our shutdown message,
  3059.         qmsg.msg = WMU_SysShutdown;
  3060.  
  3061.       } else {
  3062.  
  3063.         // If here, we posted the WM_QUIT message, so break out of
  3064.         // the message loop
  3065.         break;
  3066.       }
  3067.     }
  3068.  
  3069.     // This is not a WM_QUIT message, intercept all other
  3070.     // messages intended for the NULL window
  3071.     if (qmsg.hwnd == NULLHANDLE) {
  3072.  
  3073.       // Pass all NULL window messages to the NULL window handler
  3074.       NullMsg (qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2);
  3075.  
  3076.     } else {
  3077.  
  3078.       // This is not a WM_QUIT message, nor is it intended for the NULL
  3079.       // window.  Pass this message to the message filter hook for
  3080.       // processing.
  3081.       if (!WinCallMsgFilter (hab, (PQMSG) &qmsg, 0)) {
  3082.  
  3083.         // Filter hook has not cancelled the message, so dispatch
  3084.         // the message to the proper window
  3085.         WinDispatchMsg (hab, &qmsg);
  3086.       }
  3087.     }
  3088.   }
  3089.  
  3090. Credit:  Matt Osborn 
  3091.  
  3092.  
  3093. ΓòÉΓòÉΓòÉ 8.15. When I pass a structure to WinCreateWindow, sometimes it doesn't work! ΓòÉΓòÉΓòÉ
  3094.  
  3095. Put the size of the structure as the first word. 
  3096.  
  3097.  
  3098. ΓòÉΓòÉΓòÉ 8.16. How do I use type filtering in 2.0's open dlg? ΓòÉΓòÉΓòÉ
  3099.  
  3100. It's broken in 2.0GA, fixed in 2.0's service pak. 
  3101.  
  3102.  
  3103. ΓòÉΓòÉΓòÉ 8.17. When minimizing, my dialog box is overwriting my icon! ΓòÉΓòÉΓòÉ
  3104.  
  3105. In the WM_MINMAXFRAME message hide the offending control. 
  3106.  
  3107.     case WM_MINMAXFRAME:
  3108.       {
  3109.         PSWP pswp; /* pos change structure */
  3110.  
  3111.         /* hide list box when minimized so it doesn't overwrite icon */
  3112.         pswp = PVOIDFROMMP( mp1 );
  3113.         WinShowWindow(
  3114.           WinWindowFromID( hwnd, IDD_FILES ),
  3115.           !(pswp->fs & SWP_MINIMIZE)
  3116.         );
  3117.       }
  3118.       break;
  3119.  
  3120.  
  3121. ΓòÉΓòÉΓòÉ 8.18. How do I make a multi-column listbox? ΓòÉΓòÉΓòÉ
  3122.  
  3123. Use the container in details view.  If you just have to use a list box: 
  3124.  
  3125. Here is an extract from my dialog box procedure that produces a two-column list 
  3126. box. 
  3127.  
  3128. In this example there is only one list box, so I don't have to worry about 
  3129. which control is involved.  In this example, a blank is used to separate the 
  3130. first and second column.  You could use tabs or any other sort of separator 
  3131. character.  You could also draw anything you wanted in the list box item, 
  3132. including bit maps, colors, other fonts, etc. 
  3133.  
  3134. This is not a complete program, of course, but does show the details of 
  3135. handling a multi-column list box. 
  3136.  
  3137. /******************** Dialog Box Procedure ******************************/
  3138.  
  3139. MRESULT EXPENTRY SelectDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  3140. {
  3141.     HPS     hPS;                 /* Handle to the presentation space */
  3142.     FONTMETRICS FontMetrics;     /* Metrics of default font */
  3143.     CHAR    pszItemText[MAX_ITEM_TEXT_LENGTH];
  3144.     CHAR    *s;
  3145.     OWNERITEM FAR *poi;          /* Pointer to owner item structure */
  3146.     RECTL   rcl;                 /* Rectangle for writing */
  3147.     COLOR   clrForeGround;
  3148.     COLOR   clrBackGround;
  3149.  
  3150.     switch (msg)
  3151.         {
  3152.         case WM_INITDLG:   /* Initialize the list box */
  3153.  
  3154.             FillCfgListBox (hwnd);     /* Fill the list box */
  3155.  
  3156.             return (FALSE);
  3157.  
  3158.  
  3159.         case WM_MEASUREITEM:     /* Measure text height */
  3160.  
  3161.             hPS = WinGetPS (hwnd);     /* Get handle to presentation space */
  3162.             GpiQueryFontMetrics (hPS, (LONG) sizeof (FONTMETRICS),
  3163.                                  &FontMetrics);
  3164.         WinReleasePS (hPS);        /* Release the presentation space */
  3165.  
  3166.             return (FontMetrics.lMaxBaselineExt);
  3167.  
  3168.  
  3169.         case WM_DRAWITEM:      /* Draw a list box entry */
  3170.  
  3171.             poi = mp2;               /* Get address of owner item */
  3172.  
  3173.             if (poi->fsState == TRUE)  /* Is this cell to be highlighted? */
  3174.             {                          /* Yes, use highlight attributes */
  3175.             clrForeGround = SYSCLR_HILITEFOREGROUND;
  3176.             clrBackGround = SYSCLR_HILITEBACKGROUND;
  3177.             }
  3178.             else               /* No, use normal attributes */
  3179.             {
  3180.             clrForeGround = CLR_NEUTRAL;
  3181.             clrBackGround = CLR_BACKGROUND;
  3182.             }
  3183.  
  3184.             WinSendMsg (poi->hwnd,     /* Get item text */
  3185.                 LM_QUERYITEMTEXT,
  3186.                 (MPARAM) MAKEULONG (poi->idItem,
  3187.                         MAX_ITEM_TEXT_LENGTH),
  3188.                         (MPARAM) pszItemText);
  3189.  
  3190.             rcl.xLeft    = poi->rclItem.xLeft;  /* Set co-ordinates */
  3191.             rcl.xRight    = poi->rclItem.xRight; /* of rectangle */
  3192.             rcl.yTop    = poi->rclItem.yTop;
  3193.             rcl.yBottom = poi->rclItem.yBottom;
  3194.  
  3195.             s = strchr (pszItemText, ' ');  /* Find first blank */
  3196.             if (s)
  3197.               *s = '\0';               /* Terminate first column here */
  3198.  
  3199.             WinDrawText (poi->hps,     /* Draw the first column */
  3200.                          -1,           /* Null-terminated string */
  3201.                          pszItemText,  /* File name is here */
  3202.                          &rcl,     /* Rectangle to draw in */
  3203.                          clrForeGround,/* Foreground color */
  3204.                          clrBackGround,/* Background color */
  3205.                      DT_LEFT | DT_VCENTER | DT_ERASERECT);
  3206.  
  3207.             if (s)               /* If there is a second column */
  3208.             {
  3209.               rcl.xLeft = 100;         /* It starts out here */
  3210.                                        /* Spacing calculations could be */
  3211.                                        /* much cleverer than this very */
  3212.                                        /* crude use of an absolute position */
  3213.                                        /* (which is not transportable */
  3214.                                        /* to different display types, as */
  3215.                                        /* between 8514 and VGA) */
  3216.                 s++;                   /* Point to beginning of text */
  3217.                 WinDrawText (poi->hps, /* Draw the second column */
  3218.                              -1,       /* Also a null-terminated string */
  3219.                              s,        /* File Description */
  3220.                              &rcl, /* Rectangle to draw in */
  3221.                              clrForeGround,  /* Colors are same as */
  3222.                              clrBackGround,  /* before */
  3223.                              DT_LEFT | DT_VCENTER);
  3224.             }
  3225.  
  3226.                 /* If fsState || fsStateOld and return TRUE, then */
  3227.                 /* control will invert the rectangle -- not what */
  3228.                 /* we want.  Tell control not do do anything like that! */
  3229.  
  3230.             poi->fsState = poi->fsStateOld = FALSE;
  3231.  
  3232.             return (TRUE); /* Say we did it */
  3233.  
  3234. ... case statements for rest of program ...
  3235.  
  3236. Credit:  Guy Scharf 
  3237.  
  3238.  
  3239. ΓòÉΓòÉΓòÉ 8.19. How do I create my own Master Help Index? ΓòÉΓòÉΓòÉ
  3240.  
  3241. I talked with the owner of the Master Index, and she said there is no problem 
  3242. with using a like index to view online documentation for your application. 
  3243. There are just a few catches: 
  3244.  
  3245.  1. The documentation must be compiled as an .HLP file and not an .INF file. 
  3246.     Note that this is the default for IPFC. 
  3247.  
  3248.  2. The tagged indexed entries must have the "global" attribute. For example: 
  3249.  
  3250.    :i1 global.giving examples 
  3251.  
  3252.    or: 
  3253.  
  3254.    :i1 id=examp global.giving examples 
  3255.  
  3256.  3. The Index executable is a WPS object, not a standalone application. You 
  3257.     will need to create your own copy of the object (instance) of class Mindex, 
  3258.     either by using a REXX script  (e.g. SysCreateObject()) or within your app 
  3259.     (e.g. WinCreateObject()). 
  3260.  
  3261.     For a REXX example: 
  3262.  
  3263.             CALL   SysCreateObject  "Mindex", "Title", "<WP_DESKTOP>",
  3264.                                     "INDEX=MYFILE;OBJECTID=<MY_INDEX>"
  3265.  
  3266.     where MYFILE can be an environmental variable set to the path or filespec 
  3267.     of your .HLP files, or it can be the actual filespec itself (e.g. 
  3268.     INDEX=c:\myapp\myfile.hlp ). Note too that files can be concatenated (e.g. 
  3269.     INDEX=c:\myapp\myfile.hlp+c:\yourapp\yourfile.hlp). 
  3270.  
  3271.  4. Objects of Mindex class CAN NOT be subclassed. There are no public methods 
  3272.     in this class and it must be used as is. 
  3273.  
  3274. Credit:  John Webb 
  3275.  
  3276.  
  3277. ΓòÉΓòÉΓòÉ 8.20. How do I change the font in an MLE? ΓòÉΓòÉΓòÉ
  3278.  
  3279. How do I change the font in an MLE?  WinSetPresParms doesn't work. 
  3280.  
  3281. This is a function I used in 1.x to set the font for an MLE (haven't ported it 
  3282. yet but it should be the same). I pass it the parent hwnd of the MLE, the MLE's 
  3283. id, a facename, a pointsize, the maximum height for an outline font, and 
  3284. fsSelection (FATTR_SEL_BOLD, etc). It first tries to match on pointsize and 
  3285. facename. If it can't it uses an outline font with the height requested. 
  3286.  
  3287.  VOID EXPENTRY UtlSetMleFont( HWND hwndParent, USHORT usMleId, PSZ szFacename,
  3288.                               USHORT usPointSize, LONG lMaxHeight,
  3289.                               USHORT fsSelection )
  3290.  {
  3291.      PFONTMETRICS pfm;
  3292.      HDC          hdc;
  3293.      HPS          hps;
  3294.      HWND         hwndMle;
  3295.      LONG         lHorzRes, lVertRes, lRequestFonts = 0, lNumberFonts;
  3296.      FATTRS       fat;
  3297.      SHORT        sOutlineIndex = -1;
  3298.      INT          i;
  3299.  
  3300.      (void) memset( &fat, 0, sizeof( FATTRS ) );
  3301.      fat.usRecordLength  = sizeof( FATTRS );
  3302.      fat.fsSelection     = fsSelection;
  3303.      strcpy( fat.szFacename, szFacename );
  3304.      hwndMle = WinWindowFromID( hwndParent, usMleId );
  3305.      hps = WinGetPS( hwndMle );
  3306.      hdc = GpiQueryDevice( hps );
  3307.      DevQueryCaps( hdc, CAPS_HORIZONTAL_FONT_RES, 1L, &lHorzRes );
  3308.      DevQueryCaps( hdc, CAPS_VERTICAL_FONT_RES,   1L, &lVertRes );
  3309.      lNumberFonts = GpiQueryFonts( hps, QF_PUBLIC, szFacename,
  3310.                                    &lRequestFonts, 0L, NULL);
  3311.      pfm = malloc( (SHORT) lNumberFonts * sizeof( FONTMETRICS ) );
  3312.      GpiQueryFonts( hps, QF_PUBLIC, szFacename,
  3313.                     &lNumberFonts, (LONG) sizeof( FONTMETRICS ), pfm );
  3314.      for( i = 0; i < (USHORT) lNumberFonts; i++ )
  3315.      {
  3316.          if( pfm[ i ].fsDefn & 1 )
  3317.          {
  3318.              sOutlineIndex = (SHORT) i;
  3319.              continue;
  3320.          }
  3321.  
  3322.          if (pfm[ i ].sXDeviceRes == (SHORT) lHorzRes &&
  3323.              pfm[ i ].sYDeviceRes == (SHORT) lVertRes &&
  3324.              pfm[ i ].sNominalPointSize == (SHORT) (usPointSize * 10) )
  3325.          {
  3326.              fat.lMatch      = pfm[ i ].lMatch;
  3327.              fat.lMaxBaselineExt = pfm[ i ].lMaxBaselineExt;
  3328.              fat.lAveCharWidth     = pfm[ i ].lAveCharWidth;
  3329.              break;
  3330.          }
  3331.      }
  3332.  
  3333.      if( i >= (USHORT) lNumberFonts )
  3334.          if( sOutlineIndex >= 0 )
  3335.              if( lMaxHeight )
  3336.              {
  3337.                  fat.fsFontUse = FATTR_FONTUSE_OUTLINE;
  3338.                  if( !(fat.usCodePage = pfm[ sOutlineIndex ].usCodePage) )
  3339.                      fat.usCodePage  = 850;
  3340.                  fat.lMaxBaselineExt = lMaxHeight;
  3341.                  WinSendMsg( hwndMle, MLM_SETFONT, MPFROMP( &fat ), 0 );
  3342.              }
  3343.      WinSendMsg( hwndMle, MLM_SETFONT, MPFROMP( &fat ), 0 );
  3344.      WinReleasePS( hps );
  3345.      free( pfm );
  3346.  }
  3347.  
  3348. Credit:  Rick Fishman 
  3349.  
  3350.  
  3351. ΓòÉΓòÉΓòÉ 8.21. How do I attach Instance data to window created with WinCreateStdWindow? ΓòÉΓòÉΓòÉ
  3352.  
  3353. I always use the two call to WinCreateWindow() method,    instead of the 
  3354. WinCreateStdWindow() method,  because the latter does not allow you to set 
  3355. instance data before your winproc is called for the first time. 
  3356.  
  3357. Here's a cset/2 program (icc /Ss+ /W3 /Se /B"/pm:pm" foo.c): 
  3358.  
  3359.  #define INCL_PM
  3360.  #include <os2.h>
  3361.  
  3362.  typedef struct _mydata {
  3363.      HWND hwndFrame;
  3364.      HWND hwndClient;
  3365.      char whatever[100];
  3366.  }MYDATA;
  3367.  
  3368.  static MRESULT EXPENTRY WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3369.  {
  3370.      MYDATA *mine;
  3371.  
  3372.     mine = (MYDATA *)WinQueryWindowPtr(hwnd, 0);  // will be null for WM_CREATE
  3373.      switch(msg){
  3374.          case WM_CREATE:
  3375.              mine = (MYDATA *)mp1;
  3376.              WinSetWindowPtr(hwnd, 0, mine);
  3377.              break;
  3378.          case WM_ERASEBACKGROUND:
  3379.              return (MRESULT)TRUE;
  3380.          default:
  3381.             return WinDefWindowProc(hwnd, msg, mp1, mp2);
  3382.      }
  3383.      return 0;
  3384.  }
  3385.  
  3386.  void main(void)
  3387.  {
  3388.      HAB hab;
  3389.      HMQ hmq;
  3390.      QMSG qmsg;
  3391.      char *class = "foo";
  3392.      FRAMECDATA fcdata;  /* frame creation data */
  3393.      MYDATA mydat;
  3394.  
  3395.      hab = WinInitialize(0);
  3396.      hmq = WinCreateMsgQueue(hab, hmq);
  3397.  
  3398.      WinRegisterClass(hab, class, WinProc, 0, sizeof(MYDATA *));
  3399.  
  3400.      /* create frame window (WC_FRAME) */
  3401.      fcdata.cb = sizeof(FRAMECDATA);
  3402.      fcdata.flCreateFlags = FCF_TITLEBAR | FCF_SYSMENU |
  3403.                             FCF_SHELLPOSITION | FCF_TASKLIST |
  3404.                             FCF_SIZEBORDER | FCF_MINMAX ;
  3405.  
  3406.      fcdata.hmodResources = 0;
  3407.      fcdata.idResources   = 1;         /* resource id */
  3408.      mydat.hwndFrame = WinCreateWindow(HWND_DESKTOP, WC_FRAME, "Title",
  3409.                                        0, 0, 0, 0, 0,
  3410.                                        0,  /* no owner */
  3411.                                        HWND_TOP,fcdata.idResources,&fcdata,NULL);
  3412.  
  3413.      if(!mydat.hwndFrame)
  3414.          exit(3);
  3415.  
  3416.      /* WinProc() has not been called yet */
  3417.  
  3418.      /* Create Client window: */
  3419.      mydat.hwndClient = WinCreateWindow(mydat.hwndFrame, class, "text",
  3420.                          0, 0, 0, 0, 0,
  3421.                          mydat.hwndFrame,    /* frame is owner */
  3422.                          HWND_TOP, FID_CLIENT,
  3423.                          &mydat, /* passed as mp1 to wm_create */
  3424.                          NULL);
  3425.  
  3426.      WinShowWindow(mydat.hwndFrame, TRUE);
  3427.  
  3428.      while(WinGetMsg(hab, &qmsg, (HWND) NULL, 0, 0))
  3429.          WinDispatchMsg(hab, &qmsg);
  3430.  
  3431.  }
  3432.  
  3433. Credit:  Peter Fitzsimmons 
  3434.  
  3435.  
  3436. ΓòÉΓòÉΓòÉ 8.22. How do I get a list of fonts? ΓòÉΓòÉΓòÉ
  3437.  
  3438. Shown is code for For v1.3.  Petzold has had a nice series on fonts in PC MAG 
  3439. from about Nov 92-present. 
  3440.  
  3441. #define INCL_DEV
  3442. #define INCL_DOSMEMMGR
  3443. #define INCL_GPILCIDS
  3444. #define INCL_WINWINDOWMGR
  3445. #define INCL_WINLISTBOXES
  3446. #include <os2.h>
  3447. #include <stdio.h>
  3448.  
  3449. VOID EXPENTRY FntQueryList(hwnd)
  3450. HWND hwnd; // listbox handle
  3451.   {
  3452.   PFONTMETRICS pfm;
  3453.   HDC          hdc;
  3454.   HPS          hps;
  3455.   LONG         alDevInfo[2];
  3456.   LONG         lFonts;
  3457.   LONG         lFontCnt = 0L;
  3458.   CHAR         pch[64];
  3459.   SEL          sel;
  3460.   USHORT       i;
  3461.  
  3462.   hdc = WinOpenWindowDC(hwnd);
  3463.   DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 2L, alDevInfo);
  3464.   hps = WinGetPS(hwnd);
  3465.   lFonts = GpiQueryFonts(hps, QF_PUBLIC, (PSZ)0, &lFontCnt,
  3466.                          (LONG)sizeof(FONTMETRICS), (PFONTMETRICS)0 );
  3467.   DosAllocSeg((USHORT)lFonts * sizeof(FONTMETRICS), &sel, SEG_NONSHARED);
  3468.   pfm = (PFONTMETRICS)MAKEP(sel, 0);
  3469.   GpiQueryFonts(hps, QF_PUBLIC, (PSZ)0, &lFonts,
  3470.                 (LONG)sizeof(FONTMETRICS), pfm );
  3471.   for (i = 0; i < (USHORT)lFonts; i++) {
  3472.     if (!(pfm[i].fsDefn & FM_DEFN_OUTLINE)) {
  3473.       if ((pfm[i].sXDeviceRes == (SHORT)alDevInfo[0]) &&
  3474.           (pfm[i].sYDeviceRes == (SHORT)alDevInfo[1]) ) {
  3475.             sprintf(pch, "%2d.%s",
  3476.                     pfm[i].sNominalPointSize / 10,
  3477.                     pfm[i].szFacename );
  3478.         WinSendMsg(hwnd, LM_INSERTITEM,
  3479.                    MPFROMSHORT(LIT_END), MPFROMP(pch) );
  3480.         }
  3481.       }
  3482.     }
  3483.   DosFreeSeg(sel);
  3484.   WinReleasePS(hps);
  3485.   return;
  3486.   }
  3487.  
  3488.  
  3489. ΓòÉΓòÉΓòÉ 8.23. How do I create a folder in C and put my pgm in it? ΓòÉΓòÉΓòÉ
  3490.  
  3491. /* Create our folder on the desktop */
  3492.  
  3493. HOBJECT hFolder, hObject;
  3494.  
  3495. hFolder = WinCreateObject ("wpFolder", "My Folder",
  3496.                            "OBJECTID=<MY_FOLDER>", "<WP_DESKTOP>",
  3497.                            CO_REPLACEIFEXISTS);
  3498.  
  3499. /* Now, put our object into the folder. */
  3500.  
  3501. hObject = WinCreateObject ("wpProgram", "My Online Book",
  3502.                            "EXENAME=VIEW.EXE;PARAMETERS=MYBOOK.INF;\
  3503.                            OBJECTID=<MY_BOOK>", "<MY_FOLDER>",
  3504.                            CO_REPLACEIFEXISTS);
  3505.  
  3506. What that little code snippet does is create a folder called "My Folder"
  3507. on the desktop, and puts a program object for an online book in it.
  3508. Check out the documentation on the following functions for more
  3509. information:
  3510.  
  3511. WinCreateObject
  3512. wpSetup (for information on the setup string parameter to WinCreateObj)
  3513. WPFolder (for information on the setup strings of folders)
  3514. WPProgram                      programs
  3515. etc.
  3516.  
  3517.  
  3518. ΓòÉΓòÉΓòÉ 8.24. How do I do it in REXX? ΓòÉΓòÉΓòÉ
  3519.  
  3520. You may have seen the Paradox 4.0 install script, which uses SysCreateObject to 
  3521. make a WPS object 
  3522.  
  3523. Hope they don't mind me posting a fragment of the script by: 
  3524.  
  3525. /* Rob Gordon  Borland International 6/8/92  */
  3526.  
  3527. title = "Paradox 4.0"
  3528. classname = 'WPProgram'
  3529. location = '<WP_DESKTOP>'
  3530. setup = 'PROGTYPE=WINDOWEDVDM;EXENAME='pdoxpath'paradox.exe;
  3531.   STARTUPDIR='pdoxpath';SET DPMI_DOS_API=ENABLED;
  3532.   SET DPMI_MEMORY_LIMIT=4;ICONFILE 'pdoxpath'pdoxos2.ico;'
  3533.  
  3534. BldObj:
  3535. call charout , 'Building : 'title
  3536. result = SysCreateObject(classname, title, location, setup)
  3537.  
  3538.  
  3539. ΓòÉΓòÉΓòÉ 8.25. How do I use the Font dialog (WinFontDlg)? ΓòÉΓòÉΓòÉ
  3540.  
  3541. FIRST:  make your stack huge (>32K)  It is sparsely allocated and you only use 
  3542. what you need. Here's some code: 
  3543.  
  3544.  FONTDLG fontdlg ;
  3545.  FONTMETRICS fm ;
  3546.  CHAR            szBuf [200] ;
  3547.  CHAR            szFamily [CCHMAXPATH] ;
  3548.  static CHAR     szTitle [] = "Fonts Dialog" ;
  3549.  static CHAR     szMsgBoxTitle [] = "Result from 'WinFontDlg ()'" ;
  3550.  static CHAR     szPreview [] = "We hold these truths to be self-evident ..." ;
  3551.  
  3552.  // Here, get an HPS and then do a WinQueryFontMetrics.
  3553.  // Continuing ...
  3554.  
  3555.  memset ((void *) &fontdlg, 0, sizeof (FONTDLG)) ;
  3556.  fontdlg.cbSize = sizeof (FONTDLG) ;
  3557.  fontdlg.hpsScreen = WinGetScreenPS (HWND_DESKTOP) ;
  3558.  fontdlg.hpsPrinter = NULLHANDLE ;
  3559.  fontdlg.pszTitle = szTitle ;
  3560.  fontdlg.pszPreview = szPreview ;
  3561.  fontdlg.pfnDlgProc = NULL ;
  3562.  strcpy (szFamily, fm.szFamilyname) ;
  3563.  fontdlg.pszFamilyname = szFamily ;
  3564.  fontdlg.usFamilyBufLen = sizeof (szFamily) ;
  3565.  fontdlg.fxPointSize = MAKEFIXED (fm.sNominalPointSize / 10, 0) ;
  3566.  fontdlg.fl = FNTS_CENTER | FNTS_HELPBUTTON |
  3567.      FNTS_INITFROMFATTRS | FNTS_NOSYNTHESIZEDFONTS |
  3568.      FNTS_RESETBUTTON ;
  3569.  fontdlg.sNominalPointSize = fm.sNominalPointSize ;
  3570.  fontdlg.flType = (LONG) fm.fsType ;
  3571.  fontdlg.clrFore = CLR_NEUTRAL ;
  3572.  fontdlg.clrBack = CLR_BACKGROUND ;
  3573.  fontdlg.usWeight = fm.usWeightClass ;
  3574.  fontdlg.usWidth = fm.usWidthClass ;
  3575.  
  3576.  hwndDlg = WinFontDlg (HWND_DESKTOP, hwnd, &fontdlg) ;
  3577.  
  3578. Credit: Wayne Kovsky 
  3579.  
  3580.  
  3581. ΓòÉΓòÉΓòÉ 8.26. How do I take control of frame sizing? ΓòÉΓòÉΓòÉ
  3582.  
  3583. I want to "subclass" the Window Frame Class to allow me to control the size of 
  3584. my main window when it's resized by the mouse. I want to control the steps it 
  3585. take to resize too, (ie: by 8x8 steps). 
  3586.  
  3587. --- CUT --- CUT ---- .H file --- CUT --- 
  3588.  
  3589. HWND APIENTRY WinCreateMBWindow(
  3590.  
  3591.   HWND hwndParent,
  3592.   ULONG flStyle,
  3593.   PULONG pflCreateFlags,
  3594.   PSZ pszClientClass,
  3595.   PSZ pszTitle,
  3596.   ULONG styleClient,
  3597.   HMODULE hmod,
  3598.   USHORT idResources,
  3599.   PHWND phwndClient);
  3600.  
  3601.  
  3602. #define HMODFROMMP(mp)    ((USHORT)(ULONG)(mp))
  3603.  
  3604. #define MB_CHILD_SIZE           WM_USER+204
  3605.           //Sent from child to frame indicating the new
  3606.           //requested size of the child area.  (high&width in MP1)
  3607.           //If ChildMax is shrinking below current size,
  3608.           //    frame is redused, and evt scroll bars is hidden.
  3609.           //If Child is growing
  3610.           //   MP2=True -> grows frame to contain maximized child
  3611.           //   MP2=False-> enables scroll bars, keeps size.
  3612.  
  3613. #define MB_FIX_N       0x1 //Fix north border when sizing
  3614. #define MB_FIX_E       0x2 //Fix east  border when sizing
  3615.  
  3616. #define MB_FIX_NE       0x3 //Fix north east corner when sizing
  3617. #define MB_FIX_SE       0x2 //Fix south east corner when sizing
  3618. #define MB_FIX_NW       0x1 //Fix north west corner when sizing
  3619. #define MB_FIX_SW       0x0 //Fix south west corner when sizing
  3620.  
  3621. #define MB_QCHILD_SIZE_MAX     WM_USER+205
  3622.            //Sent from frame to child to queryw
  3623.            //max size of the child area.  (h&w in MR)
  3624.            //Used when sizing to determin if scroll bars are ness.
  3625.  
  3626. #define MB_QCHILD_GRID     WM_USER+206
  3627.            //Sent from frame to child before tracking
  3628.            //Child supposed to return x&y granularity in MR
  3629.  
  3630. #define MB_CREATE          WM_USER+207  //Internally shipped command.
  3631.  
  3632. typedef struct _FRM_DTA { /* Fram data */
  3633.     PFNWP    oldProc;
  3634.     SHORT    nTrkCnr,nYSclHor,nXSclVer,nTitle;
  3635.     SHORT    xMax,yMax;    //Max size of Client in PIX
  3636.     SHORT    ScrMaxX,ScrMaxY;
  3637.     POINTL   ptlBdr;
  3638.     HWND     hVert,hHori;
  3639.     SHORT    xCur,yCur;    //Current size of Client in PIX
  3640.     SHORT    nCorner;      //Which corner is to be stable
  3641. } FRM_DTA;
  3642. typedef FRM_DTA FAR * PFRM_DTA;
  3643.  
  3644. --- CUT --- CUT --- .C file --- CUT --- CUT --- 
  3645.  
  3646. HWND    APIENTRY WinCreateMBWindow(HWND hParent, ULONG flStyle,
  3647.                                    PULONG pflCreate, PSZ pszClientClass,
  3648.                                    PSZ pszTitle, ULONG styleClient,
  3649.                                    HMODULE hmod,
  3650.                                    USHORT idResources, PHWND phClient)
  3651. {
  3652.   HWND         hFrame;
  3653.   PFRM_DTA     pFrm;
  3654.  
  3655.   hFrame = WinCreateStdWindow(hParent,flStyle,pflCreate,pszClientClass,
  3656.                               pszTitle,styleClient,hmod,idResources,phClient);
  3657.  
  3658.   //Allocate some storage for local parameters, and initialize it
  3659.   pFrm=malloc(sizeof( FRM_DTA));
  3660.   memset(pFrm,0,sizeof( FRM_DTA));
  3661.  
  3662.   WinSetWindowPtr(hFrame,QWL_USER,(PVOID) pFrm);
  3663.  
  3664.   pFrm->oldProc= WinSubclassWindow(hFrame,newFrameProc);
  3665.  
  3666.   //Now window is setup:
  3667.  
  3668.   WinSendMsg(hFrame,MB_CREATE,MP0,MP0);    //My own WM_CREATE
  3669.  
  3670.   WinShowWindow(hFrame,TRUE);
  3671.  
  3672.   WinUpdateWindow(hFrame);
  3673.   return hFrame;
  3674. }
  3675.  
  3676. VOID GetChildMax(HWND hFrame, PFRM_DTA    pFrm)
  3677. { MRESULT mr;
  3678.   mr = WinSendMsg(WinWindowFromID(hFrame,FID_CLIENT),
  3679.                   MB_QCHILD_SIZE_MAX,MP0,MP0);
  3680.   pFrm->xMax=SHORT1FROMMR(mr);
  3681.   pFrm->yMax=SHORT2FROMMR(mr);
  3682. }
  3683.  
  3684. #define CLIENT_PROVIDED  FALSE
  3685. #define FRAME_PROVIDED     TRUE
  3686.  
  3687. BOOL WinCalcFrameSWP(HWND hwnd, PSWP pSWP, BOOL bFrame)
  3688. { //    TRUE       Frame rectangle provided
  3689.   //    FALSE      Client-area rectangle provided.
  3690.   RECTL rcl;
  3691.   BOOL bSuccess;
  3692.  
  3693.   rcl.xLeft   = pSWP->x;
  3694.   rcl.yBottom = pSWP->y;
  3695.   rcl.xRight  = pSWP->x+pSWP->cx;
  3696.   rcl.yTop    = pSWP->y+pSWP->cy;
  3697.  
  3698.   bSuccess = WinCalcFrameRect(hwnd, &rcl, bFrame );
  3699.  
  3700.   pSWP->x  =(SHORT) rcl.xLeft;
  3701.   pSWP->y  =(SHORT) rcl.yBottom;
  3702.   pSWP->cx =(SHORT) (rcl.xRight-rcl.xLeft);
  3703.   pSWP->cy =(SHORT) (rcl.yTop  -rcl.yBottom);
  3704.  
  3705.   return(bSuccess);
  3706. }
  3707.  
  3708.  
  3709. VOID SclBarEnable(HWND hwnd, PSWP pSWP, PFRM_DTA  pFrm)
  3710. {
  3711.  
  3712.   .....
  3713.  
  3714.  Your routines to determine and en/disable scroll bars 
  3715.  
  3716.   .....
  3717. /*    Part of my code */
  3718.   swpClient = *(pSWP);
  3719.   WinCalcFrameSWP(hwnd, &swpClient, FRAME_PROVIDED);
  3720.   if (swpClient.cx >= pFrm->xMax-1)
  3721.   { //Turn off horisontal scroll bar
  3722.     WinSetParent(pFrm->hHori,HWND_OBJECT ,FALSE);
  3723.     nUpdt = FCF_HORZSCROLL;
  3724.   }  /* code for enabling left out..... */
  3725.  
  3726.   if (nUpdt != 0)
  3727.   {
  3728.     WinSendMsg (hwnd, WM_UPDATEFRAME, MPFROMSHORT(nUpdt), MP0);
  3729.   }
  3730. */
  3731. }
  3732.  
  3733. /***************** Start of frame subclass procedure *****************/
  3734.  
  3735. MRESULT  EXPENTRY newFrameProc( HWND hwnd, USHORT msg,
  3736. MPARAM mp1, MPARAM mp2 )
  3737.  
  3738. { PSWP        pSWP;
  3739.   PFNWP     oldProc;
  3740.   PFRM_DTA  pFrm;
  3741.  
  3742.   pFrm=(PFRM_DTA)WinQueryWindowPtr(hwnd,QWL_USER);
  3743.   oldProc=pFrm->oldProc;
  3744.  
  3745.   switch(msg)
  3746.   {
  3747.     case MB_CREATE:
  3748.       //Start hiding scroll bars
  3749.       pFrm->hVert  = WinWindowFromID(hwnd,FID_VERTSCROLL);
  3750.       WinSetParent(pFrm->hVert,HWND_OBJECT ,FALSE);
  3751.       pFrm->nYSclHor = 0;
  3752.     break;
  3753.  
  3754.     case WM_MINMAXFRAME:
  3755.     { SWP swpClient;
  3756.       pSWP=(PSWP) PVOIDFROMMP(mp1);
  3757.       pSWP->fs |= SWP_SIZE;
  3758.  
  3759.       GetChildMax(hwnd, pFrm);
  3760.  
  3761.       if (pSWP->fs & SWP_MAXIMIZE) //MaxiMizeing Operation
  3762.       {
  3763.         //tprintf("WM_MINMAXFRAME SWP_MAXIMIZE FS: %X┬á",pSWP->fs);
  3764.         if ((0!=pFrm->xMax) && (0!=pFrm->yMax))
  3765.         { //I have no data for all of screen, so act as Windowed OS/2
  3766.  
  3767.           memset(&swpClient,0,sizeof(swpClient));
  3768.           swpClient.cx=pFrm->xMax;
  3769.           swpClient.cy=pFrm->yMax;
  3770.           WinCalcFrameSWP(hwnd, &swpClient,CLIENT_PROVIDED);
  3771.  
  3772.           pSWP->cx = swpClient.cx;
  3773.           pSWP->cy = swpClient.cy;
  3774.  
  3775.           pSWP->y  = pFrm->ScrMaxY - swpClient.cy + (SHORT)pFrm->ptlBdr.y;
  3776.  
  3777.  
  3778.           SclBarEnable(hwnd, pSWP, pFrm);
  3779.  
  3780.           return MRFROMSHORT(FALSE);
  3781.         }
  3782.       }
  3783.  
  3784.       if (pSWP->fs & SWP_RESTORE) //MiniMizeing Operation
  3785.  
  3786. ??? (restore i guess) 
  3787.  
  3788.       {
  3789.         //tprintf("WM_MINMAXFRAME SWP_RESTORE FS: %X┬á",pSWP->fs);
  3790.         if ((0!=pFrm->xMax) && (0!=pFrm->yMax))  //Why do I need this?
  3791.         {
  3792.           return MRFROMSHORT(FALSE);
  3793.         }
  3794.       }
  3795.     }
  3796.     return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  3797.  
  3798.  
  3799.     case WM_QUERYTRACKINFO:
  3800.     {
  3801.       PTRACKINFO pTI;
  3802.       LONG i;
  3803.  
  3804.       if (TF_MOVE <= SHORT1FROMMP(mp1))
  3805.       {
  3806.         pFrm->nTrkCnr= 0;
  3807.         return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  3808.       }
  3809.  
  3810.       pTI = (PTRACKINFO) PVOIDFROMMP (mp2);  //Get structure pointer;
  3811.       //tprintf("@+WM_QUERYTRACKINFO FS: %X┬á",pTI->fs);
  3812.       if ((*oldProc)(hwnd, msg, mp1, mp2)==0) return MRFROMSHORT(FALSE);
  3813.  
  3814.       GetChildMax(hwnd, pFrm);
  3815.       if ((0!=pFrm->xMax) && (0!=pFrm->yMax))
  3816.       { //Setup track info structure
  3817.         pTI->ptlMaxTrackSize.x = (LONG) pFrm->xMax;
  3818.         pTI->ptlMaxTrackSize.y = (LONG) pFrm->yMax;
  3819.  
  3820.         WinCalcFrameRect(hwnd, &(pTI->rclTrack), FRAME_PROVIDED );
  3821.  
  3822.         { MRESULT mr;
  3823.           mr = WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),
  3824.                           MB_QCHILD_GRID,MP0,MP0);
  3825.           if (NULL!=mr)
  3826.           {
  3827.             pTI->cxGrid  = SHORT1FROMMR(mr);
  3828.             pTI->cyGrid  = SHORT2FROMMR(mr);
  3829.  
  3830.             //Setting height of client to integral cyGrid
  3831.             i = (pTI->rclTrack.yTop - pTI->rclTrack.yBottom)/pTI->cyGrid;
  3832.             pTI->rclTrack.yTop = i * pTI->cyGrid + pTI->rclTrack.yBottom;
  3833.  
  3834.             pTI->fs    |= TF_GRID;
  3835.             pFrm->nTrkCnr= WM_QUERYTRACKINFO;
  3836.             //Used in WM_ADJUSTWINODWPOS
  3837.           }
  3838.         }
  3839.       }
  3840.       return MRFROMSHORT(TRUE);
  3841.     }
  3842.     break;
  3843.  
  3844.     case WM_ADJUSTWINDOWPOS:
  3845.     { RECTL rcl;
  3846.       pSWP=(PSWP) PVOIDFROMMP(mp1);
  3847.  
  3848.       if (pSWP->fs & (SWP_SIZE | SWP_MOVE | SWP_MAXIMIZE))
  3849.       {
  3850.         GetChildMax(hwnd, pFrm);
  3851.         if (WM_QUERYTRACKINFO==pFrm->nTrkCnr)
  3852.           //As a result of tracking
  3853.         {
  3854.           //Go from client to frame values
  3855.           WinCalcFrameSWP(hwnd, pSWP, CLIENT_PROVIDED);
  3856.         }
  3857.  
  3858.         pFrm->nTrkCnr     = 0;
  3859.  
  3860.         SclBarEnable(hwnd, pSWP, pFrm);
  3861.       }
  3862.       return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  3863.     }
  3864.     break;
  3865.  
  3866.     case MB_CHILD_SIZE:        //xCur,yCur
  3867.     { SWP swp;
  3868.  
  3869. ............. do your actions as responce to client resize request (Change of 
  3870. fontsize for instance) 
  3871.  
  3872.  
  3873.       return (MRESULT)TRUE;
  3874.     }
  3875.     break;
  3876.  
  3877.     default:
  3878.     break;
  3879.   }
  3880.   return (MRESULT)(*oldProc)(hwnd, msg, mp1, mp2);
  3881. }
  3882.  
  3883. A lot is deleted (Som is very application specific), but i hope you get the 
  3884. general picture. 
  3885.  
  3886. Credit:  Henrik Wahlberg 
  3887.  
  3888.  
  3889. ΓòÉΓòÉΓòÉ 8.27. How do I use the 16-bit EPM toolkit? ΓòÉΓòÉΓòÉ
  3890.  
  3891. Since there were a few requests, here are the changes I made to get the ESIMPLE 
  3892. example from the EPM Toolkit to work with the C-Set++ compiler. The ETK DLLs 
  3893. are 16-bit and need to be thunked to be called from a 32-bit app. Since I was 
  3894. playing around, some of the changes were not necessary to get the program to 
  3895. run.  Changes are in DIFF format. 
  3896.  
  3897. **** Changes to EDLL.H ****
  3898. 254a255
  3899. > #pragma pack(2)
  3900. 259,263c260,264
  3901. <    PSWP   pswp;         // positioning of edit window
  3902. <    PSZ    filename;     // file to be edited (with wildcard)
  3903. <    PVOID  hEditPtr;     // handle to editor pointer icon.
  3904. <    PVOID  hMarkPtr;     // handle to mark pointer icon.
  3905. <    PVOID  hEditorIcon;  // editor ICON.
  3906. >    PSWP _Seg16   pswp;         // positioning of edit window
  3907. >    PSZ _Seg16    filename;     // file to be edited (with wildcard)
  3908. >    HPOINTER  hEditPtr;  // handle to editor pointer icon.
  3909. >    HPOINTER  hMarkPtr;  // handle to mark pointer icon.
  3910. >    PVOID _Seg16  hEditorIcon;  // editor ICON.
  3911. 267,269c268,270
  3912. <    PSZ    exfile;       // pre-compiled macro code file (EPM.EX)
  3913. <    PSZ    topmkr;       // top and bottom of file marker
  3914. <    PSZ    botmkr;       //
  3915. ---
  3916. >    PSZ _Seg16    exfile;       // pre-compiled macro code file (EPM.EX)
  3917. >    PSZ _Seg16    topmkr;       // top and bottom of file marker
  3918. >    PSZ _Seg16    botmkr;       //
  3919. 271,272c272,273
  3920. <    PSZ    exsearchpath; // a set of paths to search for ex's files
  3921. <    PSZ    exe_path;     // path where the application started
  3922. ---
  3923. >    PSZ _Seg16    exsearchpath; // a set of paths to search for ex's files
  3924. >    PSZ _Seg16    exe_path;     // path where the application started
  3925. 275c276,277
  3926. < typedef EDITORINFO far *PEDITORINFO;
  3927. ---
  3928. > typedef EDITORINFO * PEDITORINFO;
  3929. > #pragma pack()
  3930. 280c282
  3931. < #define ETKENTRY _loadds
  3932. ---
  3933. > #define ETKENTRY CDECL16
  3934. 285,286c287,288
  3935. < PSZ     ETKENTRY EtkRegister( HAB hab, ULONG class_style );
  3936. < USHORT ETKENTRY EtkCreate( PEDITORINFO epm_p, PHWND hEwnd_p);
  3937. ---
  3938. > PSZ _Seg16    ETKENTRY EtkRegister( HAB hab, ULONG class_style );
  3939. > USHORT ETKENTRY EtkCreate( PEDITORINFO _Seg16 epm_p, PHWND _Seg16 hEwnd_p);
  3940. 304c306,307
  3941. < SHORT  ETKENTRY EtkSetSelection( HWND  hwndClient, LINE_INDEX_G  firstline,
  3942. ---
  3943. > SHORT  ETKENTRY EtkSetSelection( HWND  hwndClient, LINE_INDEX_G  firstline,
  3944. >    FIDType fileid);
  3945.  
  3946. **** Changes to ESIMPLE.C ****
  3947. 28a29,30
  3948. >
  3949. > #include "thunk.h"
  3950. 47a50
  3951. >    HWND hwndEditFrame;
  3952. 52c55
  3953. <
  3954. ---
  3955. >    swp.fl = SWP_MOVE | SWP_SIZE;
  3956. 58c61
  3957. <    epm.filename    = (PSZ)Fname;      // file to be edited (with wildca
  3958. ---
  3959. >    epm.filename    = Fname;           // file to be
  3960. > edited (with wildca
  3961. 64,65c67,70
  3962. <    epm.editorstyle = EDIT_STYLE_ACTIVATEFOCUS | EDIT_STYLE_DISABLEOWNERAFFECT
  3963. <                      EDIT_STYLE_CURSORON;
  3964. ---
  3965. >    epm.editorstyle = EDIT_STYLE_ACTIVATEFOCUS |
  3966. >                      EDIT_STYLE_CURSORON |
  3967. >                      EDIT_STYLE_STATUSLINE |
  3968. >                      EDIT_STYLE_MESSAGELINE;
  3969. 67,68c72,73
  3970. <    epm.pmstyle     = FCF_TITLEBAR | FCF_SIZEBORDER | FCF_VERTSCROLL;
  3971. <
  3972. ---
  3973. >    epm.pmstyle     = FCF_TITLEBAR | FCF_SIZEBORDER |
  3974. > FCF_VERTSCROLL | FCF_MIN
  3975. >    epm.font = TRUE;  // large font
  3976. 70,71c75,76
  3977. <    epm.topmkr      =                        // top and bottom file indicator
  3978. <    epm.botmkr      = (PSZ)" ╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧╤₧";
  3979. ---
  3980. >    epm.topmkr      = (PSZ)"<Top>";
  3981. > // top and bottom fi
  3982. >    epm.botmkr      = (PSZ)"<Bottom>";
  3983. 75c80
  3984. <
  3985. ---
  3986. >    epm.hini = NULLHANDLE;
  3987. 77,79c82,86
  3988. <    EtkCreate( (EDITORINFO far *)&epm, (PHWND)&hwndEdit );
  3989. <
  3990. <    return( (HWND)hwndEdit );
  3991. ---
  3992. >    EtkCreate( &epm, &hwndEdit );
  3993. >       hwndEditFrame = WinQueryWindow(hwndEdit, QW_PARENT);
  3994. >       WinSetWindowPos(hwndEditFrame, NULLHANDLE, swp.x, swp.y,
  3995. >           swp.cx, swp.cy, SWP_MOVE | SWP_SIZE);
  3996. >    return( hwndEdit );
  3997. 95c102
  3998. < MRESULT FAR PASCAL TestWndProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2
  3999. ---
  4000. > MRESULT EXPENTRY TestWndProc( HWND hwnd, USHORT msg,
  4001. > MPARAM mp1, MPARAM mp2 )
  4002. 144,146c151,155
  4003. <   case EPM_EDIT_ACTIVEHWND:
  4004. <      WinSetActiveWindow(HWND_DESKTOP,(HWND)mp1 );
  4005. <      break;
  4006. ---
  4007. > case EPM_EDIT_ACTIVEHWND:
  4008. >   {
  4009. >      WinSetActiveWindow(HWND_DESKTOP,(HWND)mp1 );
  4010. >   }
  4011. >   break;
  4012. 160c169
  4013. <                     (PSZ)mp1,
  4014. ---
  4015. >                     (PSZ)_DosSelToFlat(mp1),
  4016. 162c171
  4017. <                     NULL,
  4018. ---
  4019. >                     NULLHANDLE,
  4020. 235c244
  4021. <     hab = WinInitialize(NULL);              // Initialize app as a PM app
  4022. ---
  4023. >     hab = WinInitialize(NULLHANDLE);        // Initialize app as a PM app
  4024. 247c256
  4025. <
  4026.  
  4027. Credit:  Mat Kramer 
  4028.  
  4029.  
  4030. ΓòÉΓòÉΓòÉ 8.28. How do I get error info after using WinGetLastError()? ΓòÉΓòÉΓòÉ
  4031.  
  4032. ShowError Function: 
  4033.  
  4034. /*
  4035.  * ShowError -- for debugging: outputs (via printf) the last error;
  4036.  *    to use this, redirect the output of this program to a file and
  4037.  *    check the results in that file.
  4038.  *    Updated to display the error text in a MESSAGE BOX; ID_MSGBOX must be
  4039.  *    defined.
  4040.  */
  4041.  void ShowError(void)
  4042.  {
  4043.     PERRINFO p;
  4044.     char *cp;
  4045.     extern HAB hab;   /* kinda kludgy, should be a parameter */
  4046.  
  4047.     printf("ShowError: ");
  4048.     if((p = WinGetErrorInfo(hab)) == NULL)
  4049.        printf("NO ERROR\n");
  4050.     else
  4051.     {
  4052.        printf("idError = %#X\n", p->idError);
  4053.        cp = (char *)((ULONG)p + *(ULONG *)((ULONG)p + p->offaoffszMsg));
  4054.        printf("\"%s\"\n", cp);
  4055.        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (PSZ)cp, (PSZ)"Show Error",
  4056.                      ID_MSGBOX, MB_OK | MB_ICONEXCLAMATION);
  4057.        WinFreeErrorInfo(p);
  4058.     }
  4059.  }
  4060.  
  4061. Credit:  Justin V Frank 
  4062.  
  4063.  
  4064. ΓòÉΓòÉΓòÉ 8.29. Do you have code to save/restore the clipboard? ΓòÉΓòÉΓòÉ
  4065.  
  4066.  typedef struct _CLPBRDDATA // INFORMATION ABOUT A CLIPBOARD FORMAT
  4067.  {
  4068.     ULONG ulFormat; // The format type
  4069.     PVOID pvData;   // Pointer to the data for this format
  4070.  } CLPBRDDATA, *PCLPBRDDATA;
  4071.  
  4072.  //***************
  4073.  // Save formats
  4074.  //***************
  4075.  INT SaveClipboardData( HAB hab, PCLPBRDDATA *ppcd )
  4076.  {
  4077.     INT iFmtCount = 0;
  4078.  
  4079.     if( WinOpenClipbrd( hab ) )
  4080.     {
  4081.        ULONG ulNextFmt, ulPrevFmt = 0;
  4082.  
  4083.        ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4084.        while( ulNextFmt )
  4085.        {
  4086.           iFmtCount++;
  4087.           ulPrevFmt = ulNextFmt;
  4088.           ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4089.        }
  4090.  
  4091.        if( iFmtCount )
  4092.        {
  4093.           *ppcd = (PCLPBRDDATA) malloc( sizeof( CLPBRDDATA ) * iFmtCount );
  4094.           if( *ppcd )
  4095.           {
  4096.              memset( *ppcd, 0, sizeof( CLPBRDDATA ) * iFmtCount );
  4097.               if( !GetClipboardFmts( hab, *ppcd ) )
  4098.                  iFmtCount = 0;
  4099.           }
  4100.           else
  4101.           {
  4102.              iFmtCount = 0;
  4103.              Msg( "Out of memory in SaveClipboardData" );
  4104.           }
  4105.        }
  4106.        WinCloseClipbrd( hab );
  4107.     }
  4108.     else
  4109.        Msg( "SaveClipboardData could not open the clipboard" );
  4110.  
  4111.     return iFmtCount;
  4112.  }
  4113.  
  4114.  BOOL GetClipboardFmts( HAB hab, PCLPBRDDATA pcd )
  4115.  {
  4116.     BOOL  fSuccess = TRUE;
  4117.     ULONG ulNextFmt, ulPrevFmt = 0;
  4118.  
  4119.     ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4120.     while( ulNextFmt )
  4121.     {
  4122.        pcd->ulFormat = ulNextFmt;
  4123.        switch( ulNextFmt )
  4124.        {
  4125.           case CF_TEXT:
  4126.              StoreClipboardText( hab, pcd );
  4127.              break;
  4128.           case CF_BITMAP:
  4129.              StoreClipboardBmp( hab, pcd );
  4130.              break;
  4131.           case CF_METAFILE:
  4132.              StoreClipboardMeta( hab, pcd );
  4133.              break;
  4134.           default:
  4135.              break;
  4136.        }
  4137.  
  4138.        pcd++;
  4139.        ulPrevFmt = ulNextFmt;
  4140.        ulNextFmt = WinEnumClipbrdFmts( hab, ulPrevFmt );
  4141.     }
  4142.     return fSuccess;
  4143.  }
  4144.  
  4145.  VOID StoreClipboardText( HAB hab, PCLPBRDDATA pcd )
  4146.  {
  4147.     PSZ szClipText = (PSZ) WinQueryClipbrdData( hab, CF_TEXT );
  4148.     if( szClipText )
  4149.     {
  4150.        pcd->pvData = malloc( strlen( szClipText ) + 1 );
  4151.        if( pcd->pvData )
  4152.           strcpy( pcd->pvData, szClipText );
  4153.        else
  4154.           Msg( "Out of memory in StoreClipboardText" );
  4155.     }
  4156.     else
  4157.        Msg( "StoreClipboardText found no TEXT in the clipboard" );
  4158.  }
  4159.  
  4160.  VOID StoreClipboardBmp( HAB hab, PCLPBRDDATA pcd )
  4161.  {
  4162.     HBITMAP hbmClip = WinQueryClipbrdData( hab, CF_BITMAP );
  4163.     if( hbmClip )
  4164.        pcd->pvData = (PVOID) CopyBitmap( hab, hbmClip );
  4165.     else
  4166.        Msg( "StoreClipboardBmp found no BITMAP in the clipboard" );
  4167.  }
  4168.  
  4169.  VOID StoreClipboardMeta( HAB hab, PCLPBRDDATA pcd )
  4170.  {
  4171.     HMF hmfClip = WinQueryClipbrdData( hab, CF_METAFILE );
  4172.     if( hmfClip )
  4173.     {
  4174.        HMF hmfNew = GpiCopyMetaFile( hmfClip );
  4175.        if( hmfNew == GPI_ERROR )
  4176.           Msg( "StoreClipboardMeta GpiCopyMetaFile RC = %x",
  4177.           (USHORT) WinGetLastError( hab ) );
  4178.        else
  4179.           pcd->pvData = (PVOID) hmfNew;
  4180.     }
  4181.     else
  4182.        Msg( "StoreClipboardMeta found no METAFILE in the clipboard" );
  4183.  }
  4184.  
  4185.  //******************
  4186.  // Restore formats
  4187.  //******************
  4188.  VOID RestClipboardData( HAB hab, INT iFmtCount, PCLPBRDDATA pcd )
  4189.  {
  4190.     PCLPBRDDATA pcdSave = pcd;
  4191.     INT  i;
  4192.     BOOL fFormatsExist = FALSE;
  4193.  
  4194.     for( i = 0; i < iFmtCount; i++, pcd++ )
  4195.     {
  4196.        if( pcd->ulFormat && pcd->pvData )
  4197.        {
  4198.           fFormatsExist = TRUE;
  4199.           break;
  4200.        }
  4201.     }
  4202.  
  4203.     pcd = pcdSave;
  4204.     if( fFormatsExist )
  4205.        if( WinOpenClipbrd( hab ) )
  4206.        {
  4207.           WinEmptyClipbrd( hab );
  4208.           for( i = 0; i < iFmtCount; i++, pcd++ )
  4209.           {
  4210.              switch( pcd->ulFormat )
  4211.              {
  4212.                 case 0:
  4213.                    break;
  4214.                 case CF_TEXT:
  4215.                    if( pcd->pvData )
  4216.                    {
  4217.                       RestClipboardText( hab, pcd->pvData );
  4218.                       free( pcd->pvData );
  4219.                    }
  4220.                    break;
  4221.                 case CF_BITMAP:
  4222.                    if( pcd->pvData )
  4223.                    RestClipboardBmp( hab, (HBITMAP) pcd->pvData );
  4224.                    break;
  4225.                 case CF_METAFILE:
  4226.                    if( pcd->pvData )
  4227.                       RestClipboardMeta( hab, (HMF) pcd->pvData );
  4228.                    break;
  4229.                 default:
  4230.                    break;
  4231.              }
  4232.           }
  4233.           WinCloseClipbrd( hab );
  4234.        }
  4235.        else
  4236.           Msg( "RestClipboardData could not open the clipboard" );
  4237.     free( pcdSave );
  4238.  }
  4239.  
  4240.  VOID RestClipboardText( HAB hab, PSZ szTextIn )
  4241.  {
  4242.     PSZ szTextOut = NULL;
  4243.     ULONG ulRC =
  4244.     DosAllocSharedMem( (PVOID) &szTextOut, NULL,
  4245.                        strlen( szTextIn ) + 1,
  4246.                        PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE );
  4247.     if( !ulRC )
  4248.     {
  4249.        strcpy( szTextOut, szTextIn );
  4250.        if( !WinSetClipbrdData( hab, (ULONG) szTextOut, CF_TEXT,
  4251.                                CFI_POINTER ) )
  4252.           Msg( "RestClipboardText WinSetClipbrdData failed" );
  4253.     }
  4254.     else
  4255.        Msg( "RestClipboardText DosAllocSharedMem RC: %u", ulRC );
  4256.  }
  4257.  
  4258.  VOID RestClipboardBmp( HAB hab, HBITMAP hbm )
  4259.  {
  4260.   if( !WinSetClipbrdData( hab, (ULONG) hbm, CF_BITMAP, CFI_HANDLE ) )
  4261.      Msg( "RestClipboardBmp WinSetClipbrdData failed" );
  4262.  }
  4263.  
  4264.  VOID RestClipboardMeta( HAB hab, HMF hmf )
  4265.  {
  4266.   if( !WinSetClipbrdData( hab, (ULONG) hmf, CF_METAFILE, CFI_HANDLE ) )
  4267.      Msg( "RestClipboardMeta WinSetClipbrdData failed" );
  4268.  }
  4269.  
  4270.  HBITMAP CopyBitmap( HAB hab, HBITMAP hbmIn )
  4271.  {
  4272.     BITMAPINFOHEADER2 bmih;
  4273.     HBITMAP           hbmOut = NULLHANDLE;
  4274.     HDC               hdcIn = NULLHANDLE, hdcOut = NULLHANDLE;
  4275.     HPS               hpsIn = NULLHANDLE, hpsOut = NULLHANDLE;
  4276.     POINTL            aptl[ 3 ];
  4277.     SIZEL             sizel = {0,0};
  4278.  
  4279.     hdcIn = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, NULLHANDLE );
  4280.     if( !hdcIn )
  4281.     {
  4282.        Msg( "CopyBitmap DevOpenDC for hdcIn RC = %x",
  4283.             (USHORT) WinGetLastError( hab ) );
  4284.        goto BYEBYE;
  4285.     }
  4286.  
  4287.     hdcOut = DevOpenDC( hab, OD_MEMORY, "*", 0, NULL, NULLHANDLE );
  4288.     if( !hdcOut )
  4289.     {
  4290.        Msg( "CopyBitmap DevOpenDC for hdcOut RC = %x",
  4291.             (USHORT) WinGetLastError( hab ) );
  4292.        goto BYEBYE;
  4293.     }
  4294.  
  4295.     hpsIn  = GpiCreatePS( hab, hdcIn, &sizel,PU_PELS |
  4296.                           GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
  4297.     if( !hpsIn )
  4298.     {
  4299.        Msg( "CopyBitmap GpiCreatePS for hpsIn RC = %x",
  4300.             (USHORT) WinGetLastError( hab ) );
  4301.        goto BYEBYE;
  4302.     }
  4303.  
  4304.     hpsOut = GpiCreatePS( hab, hdcOut, &sizel,PU_PELS |
  4305.                           GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
  4306.     if( !hpsOut )
  4307.     {
  4308.        Msg( "CopyBitmap GpiCreatePS for hpsOut RC = %x",
  4309.             (USHORT) WinGetLastError( hab ) );
  4310.        goto BYEBYE;
  4311.     }
  4312.  
  4313.     bmih.cbFix = sizeof( BITMAPINFOHEADER2 );
  4314.     if( !GpiQueryBitmapInfoHeader( hbmIn, &bmih ) )
  4315.     {
  4316.        Msg( "CopyBitmap GpiQueryBitmapInfoHeader for hbmIn RC = %x",
  4317.             (USHORT) WinGetLastError( hab ) );
  4318.        goto BYEBYE;
  4319.     }
  4320.  
  4321.     hbmOut = GpiCreateBitmap( hpsOut, &bmih, 0, NULL, NULL );
  4322.     if( hbmOut )
  4323.     {
  4324.        if( HBM_ERROR == GpiSetBitmap( hpsIn, hbmIn ) )
  4325.        {
  4326.           Msg( "CopyBitmap GpiSetBitmap for hpsIn RC = %x",
  4327.                (USHORT) WinGetLastError( hab ) );
  4328.           hbmOut = NULLHANDLE;
  4329.           goto BYEBYE;
  4330.        }
  4331.  
  4332.        if( HBM_ERROR == GpiSetBitmap( hpsOut, hbmOut ) )
  4333.        {
  4334.           Msg( "CopyBitmap GpiSetBitmap for hpsOut RC = %x",
  4335.                (USHORT) WinGetLastError( hab ) );
  4336.           hbmOut = NULLHANDLE;
  4337.           goto BYEBYE;
  4338.        }
  4339.  
  4340.        aptl[ 0 ].x = 0;
  4341.        aptl[ 0 ].y = 0;
  4342.        aptl[ 1 ].x = bmih.cx;
  4343.        aptl[ 1 ].y = bmih.cy;
  4344.        aptl[ 2 ].x = 0;
  4345.        aptl[ 2 ].y = 0;
  4346.  
  4347.        if( GPI_ERROR == GpiBitBlt( hpsOut, hpsIn, 3, aptl, ROP_SRCCOPY,
  4348.                                    BBO_IGNORE ) )
  4349.        {
  4350.           Msg( "CopyBitmap GpiBitBlt for hpsOut RC = %x",
  4351.                (USHORT) WinGetLastError( hab ) );
  4352.           hbmOut = NULLHANDLE;
  4353.        }
  4354.     }
  4355.     else
  4356.        Msg( "CopyBitmap GpiCreateBitmap for hbmOut RC = %x",
  4357.             (USHORT) WinGetLastError( hab ) );
  4358.  
  4359.  BYEBYE:
  4360.  
  4361.     if( hpsIn )
  4362.        GpiDestroyPS( hpsIn );
  4363.     if( hpsOut )
  4364.        GpiDestroyPS( hpsOut );
  4365.     if( hdcIn )
  4366.        DevCloseDC( hdcIn );
  4367.     if( hdcOut )
  4368.        DevCloseDC( hdcOut );
  4369.     return hbmOut;
  4370.  }
  4371.  
  4372. Credit:  Rick Fishman 
  4373.  
  4374.  
  4375. ΓòÉΓòÉΓòÉ 8.30. How do I know what item was selected in a Combo box? ΓòÉΓòÉΓòÉ
  4376.  
  4377. Catch the LN_SELECT message from the combo box, then send an LM_QUERYSELECTION 
  4378. to get the index of the selection, then a LM_QUERYITEMTEXT to get the selected 
  4379. text. 
  4380.  
  4381. Credit:  Pete Norloff 
  4382.  
  4383.  
  4384. ΓòÉΓòÉΓòÉ 8.31. How do I get a bitmap into a dialog in a DLL? ΓòÉΓòÉΓòÉ
  4385.  
  4386. You've hit on a known problem with bitmaps in dialogs in dlls. This also used 
  4387. to be a problem for icons but that appears to be working now. 
  4388.  
  4389. First, define your bitmap in your dialog like this (notice no mention of 
  4390. SS_BITMAP). It is strictly text at this point. PM can handle this when loading 
  4391. the dialog: 
  4392.  
  4393. Below are all the files necessary to create dllbitmp.exe and dlgdll.dll. Dlgdll 
  4394. has the dialog box and bitmap. Dllbitmp.exe calls DllDialog() in dlgdll.dll to 
  4395. bring up the dialog box from the dll's resource file... 
  4396.  
  4397. DLLBITMP.C: 
  4398.  
  4399.  #define  INCL_GPI
  4400.  #define  INCL_WIN
  4401.  #include <os2.h>
  4402.  #include "dllbitmp.h"
  4403.  
  4404.  #define FRAME_FLAGS  (FCF_TASKLIST | FCF_TITLEBAR   |
  4405.                        FCF_MENU     | FCF_SYSMENU    |
  4406.                        FCF_MINMAX   | FCF_SIZEBORDER |
  4407.                        FCF_SHELLPOSITION)
  4408.  #define CLIENT_CLASS "DllBitmp"
  4409.  
  4410.  
  4411.  INT main( VOID );
  4412.  VOID EXPENTRY DllDialog( HWND );
  4413.  FNWP wpClient;
  4414.  
  4415.  
  4416.  INT main( VOID )
  4417.  {
  4418.     HAB   hab;
  4419.     HMQ   hmq;
  4420.     QMSG  qmsg;
  4421.     HWND  hwndFrame, hwndClient;
  4422.     ULONG flFrame = FRAME_FLAGS;
  4423.  
  4424.     hab = WinInitialize( 0 );
  4425.     hmq = WinCreateMsgQueue( hab, 0 );
  4426.     WinRegisterClass( hab, CLIENT_CLASS, wpClient, 0, 0 );
  4427.     hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE,
  4428.                                     &flFrame,CLIENT_CLASS, NULL,
  4429.                                     0,NULLHANDLE, ID_RESOURCES,
  4430.                                     &hwndClient );
  4431.     while( WinGetMsg( hab, &qmsg, NULLHANDLE, 0, 0 ) )
  4432.        WinDispatchMsg( hab, &qmsg );
  4433.  
  4434.     WinDestroyWindow( hwndFrame );
  4435.     WinDestroyMsgQueue( hmq );
  4436.     WinTerminate( hab );
  4437.     return 0;
  4438.  }
  4439.  
  4440.  
  4441.  MRESULT EXPENTRY wpClient( HWND hwnd, ULONG msg,
  4442.                             MPARAM mp1, MPARAM mp2 )
  4443.  {
  4444.     switch( msg )
  4445.     {
  4446.        case WM_ERASEBACKGROUND:
  4447.           return (MRESULT) TRUE;
  4448.        case WM_COMMAND:
  4449.        switch( SHORT1FROMMP( mp1 ) )
  4450.        {
  4451.           case IDM_DOIT:
  4452.           {
  4453.              DllDialog( hwnd );
  4454.              return 0;
  4455.           }
  4456.        }
  4457.  
  4458.        break;
  4459.     }
  4460.     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  4461.  }
  4462.  
  4463. DLLBITMP.H: 
  4464.  
  4465.  #define ID_RESOURCES    1
  4466.  #define IDD_DOIT    100
  4467.  #define IDM_DOIT    110
  4468.  #define ID_BITMAP    1100
  4469.  #define ID_BITMAPID    1200
  4470.  
  4471. DLLBITMP.DEF: 
  4472.  
  4473.  NAME        DLLBITMP      WINDOWAPI
  4474.  PROTMODE
  4475.  HEAPSIZE    16384
  4476.  STACKSIZE    16384
  4477.  
  4478. DLLBITMP.RC: 
  4479.  
  4480.  #include <os2.h>
  4481.  #include "dllbitmp.h"
  4482.  
  4483.  
  4484.  MENU ID_RESOURCES
  4485.  {
  4486.      MENUITEM "!~DoIt", IDM_DOIT
  4487.  }
  4488.  
  4489. DLGDLL.C: 
  4490.  
  4491.  #define  INCL_DOS
  4492.  #define  INCL_GPI
  4493.  #define  INCL_WIN
  4494.  #include <os2.h>
  4495.  #include "dllbitmp.h"
  4496.  
  4497.  
  4498.  FNWP wpDlg;
  4499.  
  4500.  
  4501.  VOID EXPENTRY DllDialog( HWND hwnd )
  4502.  {
  4503.     HMODULE hmod;
  4504.  
  4505.     DosQueryModuleHandle( "DLGDLL", &hmod );
  4506.     WinDlgBox( HWND_DESKTOP, hwnd, wpDlg, hmod, IDD_DOIT, NULL );
  4507.  }
  4508.  
  4509.  
  4510.  MRESULT EXPENTRY wpDlg( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  4511.  {
  4512.     switch (msg)
  4513.     {
  4514.        case WM_INITDLG:
  4515.        {
  4516.           HWND    hwndBmp = WinWindowFromID( hwndDlg, ID_BITMAPID );
  4517.           HPS     hps = WinGetPS( hwndDlg );
  4518.           HBITMAP hbm;
  4519.           HMODULE hmod;
  4520.  
  4521.           DosQuieryModuleHandle( "DLGDLL", &hmod );
  4522.           hbm = GpiLoadBitmap( hps, hmod, ID_BITMAP, 0, 0 );
  4523.           WinSetWindowBits(hwndBmp,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f);
  4524.           WinSendMsg( hwndBmp, SM_SETHANDLE, MPFROMP( hbm ), NULL );
  4525.           WinSetWindowULong( hwndDlg, QWL_USER, (ULONG) hbm );
  4526.           WinReleasePS( hps );
  4527.           break;
  4528.        }
  4529.        case WM_DESTROY:
  4530.        {
  4531.           HBITMAP hbm = (HBITMAP) WinQueryWindowULong(hwndDlg,QWL_USER );
  4532.           GpiDeleteBitmap( hbm );
  4533.           break;
  4534.        }
  4535.     }
  4536.     return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  4537.  }
  4538.  
  4539. DLGDLL.DLG: 
  4540.  
  4541.  DLGTEMPLATE IDD_DOIT LOADONCALL MOVEABLE DISCARDABLE
  4542.  BEGIN
  4543.    DIALOG "", IDD_DOIT, 0, 0, 210, 154, FS_NOBYTEALIGN | FS_DLGBORDER |
  4544.               WS_VISIBLE | WS_CLIPSIBLINGS | WS_SAVEBITS, FCF_TITLEBAR
  4545.    BEGIN
  4546.        CONTROL "foo", ID_BITMAPID, 98, 56, 32, 32, WC_STATIC,
  4547.                SS_TEXT | DT_LEFT | DT_TOP | WS_VISIBLE
  4548.    END
  4549.  END
  4550.  
  4551. DLGDLL.DEF: 
  4552.  
  4553.  LIBRARY    DLGDLL        INITINSTANCE    TERMINSTANCE
  4554.  PROTMODE
  4555.  CODE        LOADONCALL
  4556.  DATA        LOADONCALL    MULTIPLE    NONSHARED
  4557.  EXPORTS    DllDialog
  4558.  
  4559. DLGDLL.RC: 
  4560.  
  4561.  #include <os2.h>
  4562.  #include "dllbitmp.h"
  4563.  
  4564.  
  4565.  BITMAP  ID_BITMAP "dlgdll.bmp"
  4566.  
  4567.  
  4568.  rcinclude dlgdll.dlg
  4569.  
  4570. MAKEFILE: 
  4571.  
  4572.  all: dlgdll.dll dllbitmp.exe
  4573.  
  4574.  dlgdll.dll: $*.obj $*.res
  4575.      link386 /NOI /NOE /MAP /DE /NOL $*, $*.dll,, os2386, $*
  4576.      rc $*.res $*.dll
  4577.      implib $*.lib $*.def
  4578.  
  4579.  dllbitmp.exe: $*.obj $*.def $*.res
  4580.      link386  /NOI /NOE /MAP /DE /NOL $*,,, os2386 dlgdll, $*
  4581.      rc $*.res $*.exe
  4582.  
  4583.  dllbitmp.obj: $*.c
  4584.      icc /Q+ /Ss /W3 /Kbcepr /Gm- /Gd- /Ge+ /Ti+ /O- /C $*.c
  4585.  
  4586.  dllbitmp.res: $*.rc
  4587.      rc -r $*
  4588.  
  4589.  dlgdll.obj: $*.c
  4590.      icc /Q+ /Ss /W3 /Kbcepr /Gm- /Gd- /Ge- /Ti+ /O- /C $*.c
  4591.  
  4592.  dlgdll.res: $*.rc $*.dlg
  4593.      rc -r $*
  4594.  
  4595. Credit:  Rick Fishman 
  4596.  
  4597.  
  4598. ΓòÉΓòÉΓòÉ 8.32. How does programming PM compare to programming X? ΓòÉΓòÉΓòÉ
  4599.  
  4600. Many people have said "PM is much cleaner."  Until I hear from someone I trust 
  4601. with extensive experience with both (I only know X), however, this FAQ will 
  4602. take no position. 
  4603.  
  4604. There was an unsubstantiated rumor that someone was porting an X library to 
  4605. OS/2 (X-Windows, not X-Mode or any other X), I dunno whether this has been 
  4606. substantiated or not. 
  4607.  
  4608. IBM and a few other manufacturers have built their own X servers for OS/2. 
  4609. [details?] 
  4610.  
  4611. [Colin Jensen...] 
  4612.  
  4613. I have some limited experience with X and PM.  Raw Xlib is harder to program 
  4614. than PM.  However most, if not all, of the X11 Toolkits are *easier* to use 
  4615. than PM.  I have experience comparing XView to PM. A friend of mine has 
  4616. experience with Windows versus Xt, and has the same opinion (Windows isn't that 
  4617. far off conceptually from PM). 
  4618.  
  4619.  
  4620. ΓòÉΓòÉΓòÉ 8.33. How do I put bitmaps on buttons? ΓòÉΓòÉΓòÉ
  4621.  
  4622. Stefan Gruendal (Stefan_Gruendel@wue.maus.de) writes: 
  4623.  
  4624. But to my question:  How do I build my own "smart icons", i.e. bitmaps on 
  4625. pushbuttons, that optically "move into the screen"? I didn't find any way to 
  4626. achieve this with the Toolkit's Dialog Editor.  But as mentioned above, I know 
  4627. there's a way. 
  4628.  
  4629. Starting with OS/2 2.x, a new button style was added - BS_ICON - which allows 
  4630. you to do what you are trying to accomplish.  It works, as far as I know, only 
  4631. for pushbuttons, and the icon or bitmap is taken from the resource file, whose 
  4632. resource id is specified in the pushbutton text. 
  4633.  
  4634. For example: 
  4635.  
  4636. In FOO.H: 
  4637.  
  4638. #define IDBM_BUTTON 256
  4639. #define IDPB_BUTTON 257
  4640.  
  4641. In FOO.RC: 
  4642.  
  4643. BITMAP IDBM_BUTTON BUTTON.BMP
  4644.  
  4645. In FOO.C: 
  4646.  
  4647. sprintf(achText,"#%d",IDBM_BUTTON);
  4648.  
  4649. hwndButton=WinCreateWindow(hwndClient,WC_BUTTON,achText,
  4650.                            WS_VISIBLE|BS_PUSHBUTTON|BS_ICON,
  4651.                            10,10,32,32,hwndClient,HWND_TOP,
  4652.                            IDPB_BUTTON,NULL,NULL);
  4653.  
  4654. The bitmap is stretched or compressed to fill the button. 
  4655.  
  4656. (Quoted almost directly from EDMI/2 Edition 1) 
  4657.  
  4658.  
  4659. ΓòÉΓòÉΓòÉ 8.34. Can a PM program tell if there's a previous instance of itself running? ΓòÉΓòÉΓòÉ
  4660.  
  4661. Raja Thiagarajan (sthiagar@bronze.ucs.indiana.edu) writes: 
  4662.  
  4663. Can a PM program tell if there's a previous instance of itself running?  In 
  4664. Win3.x (but apparently NOT Win32), there's a hPrevInst handle; is there an OS/2 
  4665. 2.x equivalent?  Basically, I'm thinking in terms of a program that would try 
  4666. to borrow resources from a previous instance if a previous instance is running. 
  4667. (Specifically, if my palette animation program gets started twice, the second 
  4668. instance oughta share palettes with the first instance!) 
  4669.  
  4670. What you're really asking is two questions: 
  4671.  
  4672.  1. How can I determine if a previous instance of my application is already 
  4673.     running? 
  4674.  2. How can I share resources between multiple instances of my application? 
  4675.  
  4676. To answer your first question, you need to enumerate all of the main windows 
  4677. present on the desktop, and figure out if any of them are yours. This is 
  4678. achieved using the following code: 
  4679.  
  4680. HWND queryAppInstance(PCHAR pchClassWanted)
  4681. {
  4682.    HENUM heEnum;
  4683.    HWND hwndTop;
  4684.    HWND hwndClient;
  4685.    CHAR achClass[256];
  4686.  
  4687.    heEnum=WinBeginEnumWindows(HWND_DESKTOP);
  4688.  
  4689.    hwndTop=WinGetNextWindow(heEnum);
  4690.    while (hwndTop!=NULLHANDLE) {
  4691.       hwndClient=WinWindowFromID(hwndTop,FID_CLIENT);
  4692.       if (hwndClient!=NULLHANDLE) {
  4693.          WinQueryClassName(hwndClient,sizeof(achClass),achClass);
  4694.          if (strcmp(achClass,pchClassWanted)==0) {
  4695.             WinEndEnumWindows(heEnum);
  4696.             return hwndClient;
  4697.          } /* endif */
  4698.       } /* endif */
  4699.  
  4700.       hwndTop=WinGetNextWindow(heEnum);
  4701.    } /* endwhile */
  4702.  
  4703.    WinEndEnumWindows(heEnum);
  4704.    return NULLHANDLE;
  4705. }
  4706.  
  4707. To answer your second question, the only way that I know of to share resources 
  4708. is to place them in a DLL.  The procedure to do this is as follows: 
  4709.  
  4710. o Create a dummy source file with an empty procedure in it. 
  4711. o Compile the source file and link as a DLL. 
  4712. o Add your resources to the DLL in the same manner as you would to an 
  4713.   executable. 
  4714.  
  4715. Then, when your application starts, you simply call WinLoadLibrary  (the 
  4716. preferred way) or DosLoadModule to load the DLL.  These functions return a 
  4717. handle to the DLL which must then be used in any function which loads resources 
  4718. (e.g. GpiLoadBitmap, WinLoadPointer, etc.). 
  4719.  
  4720. Note that this procedure does not require knowing the window handle of any 
  4721. previous instance of your application because OS/2 implements DLLs in a shared 
  4722. fashion (which I suspect is one of the reasons they were created in the first 
  4723. place).  All you need to know is the name of the DLL.  This technique can also 
  4724. be used to share resources between different applications. 
  4725.  
  4726. (Quoted almost directly from EDMI/2 Edition 1) 
  4727.  
  4728.  
  4729. ΓòÉΓòÉΓòÉ 9. Miscellaneous Programming ΓòÉΓòÉΓòÉ
  4730.  
  4731. This section covers non-Presentation Manager programming. 
  4732.  
  4733.  
  4734. ΓòÉΓòÉΓòÉ 9.1. Explain the SYS_DLL keywords. ΓòÉΓòÉΓòÉ
  4735.  
  4736. Actually there are three key names that exist for the app name SYS_DLL. 
  4737.  
  4738. They are: 
  4739.  
  4740. LOAD 
  4741.           DLL loaded and ordinal 1 entry point called for every msg queue 
  4742.           created in the system 
  4743.  
  4744. LOADPERPROCESS 
  4745.           DLL loaded and ordinal 1 entry point called for only the first 
  4746.           message queue created on a process 
  4747.  
  4748. LOADONETIME 
  4749.           DLL loaded and ordinal 1 entry point called for only the shell's 
  4750.           message queue (the first PM queue in the system) 
  4751.  
  4752. You would use one over another depending on the type of initialization that you 
  4753. require.  Most DLL's only need to be initialized once for the system and are 
  4754. thus LOADONETIME, some DLLs like PMCTLS have per process initialization and 
  4755. thus are LOADPERPROCESS, and then there is the very rare case of DLLs that need 
  4756. to perform some function every time a message queue is created and these are 
  4757. specified as LOAD.  Note: that anything other than LOADONETIME is a significant 
  4758. performance hit on the system.  Note: also that in addition to your 
  4759. INITIALIZATION/TERMINATION function specified in the DEF file for your DLL 
  4760. (which is a new feature in 2.0), your ORDINAL 1 entry point in your DLL is also 
  4761. called.  Be careful with this as I have seen some pretty strange results if you 
  4762. have an ordinal 1 entry point that has nothing to do with initialization.  In 
  4763. addition, remember to never ever create a message queue inside of your 
  4764. initialization routine.  Always call WinQueryAnchorBlock if you need a HAB for 
  4765. some API. 
  4766.  
  4767. As for shared resources, if you need resources on multiple processes then they 
  4768. need to be created on multiple processes as they won't be valid on any process 
  4769. other than the one you loaded.  I believe that this is the reason PMCTLS is 
  4770. LOADPERPROCESS.  You have a few options here, 1) you can store your resources 
  4771. in shared memory, and 2) for icons you can call WinSetPoinerOwner to make your 
  4772. icons shared across the entire system. 
  4773.  
  4774.  
  4775. ΓòÉΓòÉΓòÉ 9.2. How do I start another session? ΓòÉΓòÉΓòÉ
  4776.  
  4777. This small program will start any program synchronously using 
  4778. DosStartSession(). The important thing is the queue. When you specify 
  4779. SSF_RELATED_CHILD and a TermQ name, OS/2 will write the return code to the 
  4780. specified queue when the session terminates. I use this in an event scheduler 
  4781. by creating a separate thread that does reads from the queue but you can just 
  4782. as easily block on the main thread to catch the return code. That will, in 
  4783. effect, provide for synchronous execution. Note that one problem with 
  4784. SSF_RELATED_CHILD is that if the program that started the child dies, so does 
  4785. the child. 
  4786.  
  4787.  #define  INCL_DOSERRORS
  4788.  #define  INCL_DOSPROCESS
  4789.  #define  INCL_DOSQUEUES
  4790.  #define  INCL_DOSSESMGR
  4791.  #include <os2.h>
  4792.  #include <stdio.h>
  4793.  #include <stdlib.h>
  4794.  #include <string.h>
  4795.  
  4796.  #define QUEUE_NAME    "\\QUEUES\\STRTSYNC.QUE"
  4797.  
  4798.  int main( int argc, char *argv[] );
  4799.  
  4800.  int main( int argc, char *argv[] )
  4801.  {
  4802.      APIRET rc;
  4803.      HQUEUE hque;
  4804.  
  4805.      if( argc < 2 )
  4806.          return 1;
  4807.  
  4808.      rc = DosCreateQueue( &hque, QUE_FIFO | QUE_CONVERT_ADDRESS, QUEUE_NAME );
  4809.      if( !rc )
  4810.      {
  4811.          STARTDATA   stdata;
  4812.          PID         pidSession;
  4813.          CHAR        szObjFail[ 50 ];
  4814.          ULONG       ulLength, idSession;
  4815.          REQUESTDATA rd;
  4816.          PUSHORT     pusInfo = NULL;
  4817.          BYTE        bPriority;
  4818.  
  4819.          (void) memset( &stdata, 0, sizeof( stdata ) );
  4820.  
  4821.          stdata.Length       = sizeof( STARTDATA );
  4822.          stdata.FgBg         = SSF_FGBG_FORE;
  4823.          stdata.TraceOpt     = SSF_TRACEOPT_NONE;
  4824.          stdata.PgmTitle     = "Rick's Program";
  4825.          stdata.InheritOpt   = SSF_INHERTOPT_SHELL;
  4826.          stdata.SessionType  = SSF_TYPE_DEFAULT;
  4827.          stdata.PgmControl   = SSF_CONTROL_VISIBLE;
  4828.          stdata.ObjectBuffer = szObjFail;
  4829.          stdata.ObjectBuffLen= sizeof( szObjFail );
  4830.          stdata.Related      = SSF_RELATED_CHILD;
  4831.          stdata.TermQ        = QUEUE_NAME;
  4832.          stdata.PgmName      = argv[ 1 ];
  4833.  
  4834.          rc = DosStartSession( &stdata, &idSession, &pidSession );
  4835.  
  4836.          if( rc && rc != ERROR_SMG_START_IN_BACKGROUND )
  4837.          {
  4838.              printf( "DosStartSession RC(%u)\n", rc );
  4839.              return (INT) rc;
  4840.          }
  4841.  
  4842.          rc = DosReadQueue( hque, &rd, &ulLength, (PPVOID) &pusInfo, 0,
  4843.                             DCWW_WAIT, &bPriority, 0 );
  4844.  
  4845.          if( rc && rc != ERROR_QUE_EMPTY )
  4846.          {
  4847.              printf( "DosReadQueue RC(%u)\n", rc );
  4848.              return (INT) rc;
  4849.          }
  4850.  
  4851.          printf( "RetCode from Session %u: %u\n",
  4852.                   pusInfo[ 0 ], pusInfo[ 1 ]);
  4853.  
  4854.          DosCloseQueue( hque );
  4855.      }
  4856.      else
  4857.      {
  4858.          printf( "DosCreateQueue RC(%u)\n", rc );
  4859.          return (INT) rc;
  4860.      }
  4861.  
  4862.      return 0;
  4863.  }
  4864.  
  4865. Credit:  Rick Fishman 
  4866.  
  4867.  
  4868. ΓòÉΓòÉΓòÉ 9.3. How do I check if a filename is valid? ΓòÉΓòÉΓòÉ
  4869.  
  4870. Here's some code that should help.  I found that you have to look at each 
  4871. return code to see if it's really an error.  This routine does do syntax 
  4872. checking, it's just a little more complicated than before :^) 
  4873.  
  4874. #define INCL_DOSFILEMGR
  4875. #define INCL_DOSERRORS
  4876. #include <os2.h>
  4877. #include <stdio.h>
  4878.  
  4879. int main( int argc, char **argv )
  4880. {
  4881.         int         rc;
  4882.         FILESTATUS3 piBuffer;
  4883.  
  4884.         if ( argc !=2 )
  4885.         {
  4886.                 printf( "Must pass filename on command line!\n");
  4887.                 return( -1 );
  4888.         }
  4889.         else
  4890.         {
  4891.                 printf( "Checking on %s, ", argv[ 1 ] );
  4892.                 rc = DosQueryPathInfo( (PSZ)argv[1], FIL_STANDARD, &piBuffer,
  4893.                                        sizeof(FILESTATUS3));
  4894.  
  4895.                 if ( rc == 0 )
  4896.                         printf( "syntax valid and file exists\n" );
  4897.                 else
  4898.                 if ( rc == ERROR_FILE_NOT_FOUND )
  4899.                         printf( "syntax valid and file doesn't exist.\n");
  4900.                 else
  4901.                 if ( rc == ERROR_PATH_NOT_FOUND )
  4902.                         printf( "syntax valid, somthing in path was not found\n");
  4903.                 else
  4904.                 {
  4905.                         printf( "bad, rc=%d, ",rc );
  4906.                         switch( rc )
  4907.                         {
  4908.                                 case ERROR_INVALID_DRIVE:
  4909.                                         printf( "drive name does not exist\n");
  4910.                                         break;
  4911.  
  4912.                                 case ERROR_INVALID_NAME:
  4913.                                         printf( "invalid syntax for drive name\n");
  4914.                                         break;
  4915.  
  4916.                                 case ERROR_FILENAME_EXCED_RANGE:
  4917.                                         printf( "dir name and/or filename too long\n");
  4918.                                         break;
  4919.  
  4920.                                 case ERROR_SHARING_VIOLATION:
  4921.                                         printf( "sharing violation\n");
  4922.                                         break;
  4923.  
  4924.                                 case ERROR_BUFFER_OVERFLOW:
  4925.                                         printf( "buffer overflow\n");
  4926.                                         break;
  4927.  
  4928.                                 case ERROR_INVALID_LEVEL:
  4929.                                         printf( "invalid level requested\n");
  4930.                                         break;
  4931.  
  4932.                                 case ERROR_INVALID_EA_NAME:
  4933.                                         printf( "invalid EA name\n");
  4934.                                         break;
  4935.  
  4936.                                 case ERROR_EA_LIST_INCONSISTENT:
  4937.                                         printf( "EA list inconsistent\n");
  4938.                                         break;
  4939.  
  4940.                                 default:
  4941.                                         printf("Undocumented return value.\n");
  4942.                         }
  4943.                         return( -1 );
  4944.             }
  4945.             return( 0 );
  4946.         }
  4947. }
  4948.  
  4949. Credit:  Mike Brown 
  4950.  
  4951.  
  4952. ΓòÉΓòÉΓòÉ 9.4. Why should I use _beginthread instead of DosCreateThread? ΓòÉΓòÉΓòÉ
  4953.  
  4954. You must if you want to use the C runtime library. 
  4955.  
  4956.  
  4957. ΓòÉΓòÉΓòÉ 9.5. How do I open a file that is already in use? ΓòÉΓòÉΓòÉ
  4958.  
  4959. Use DosOpen with OPEN_SHARE_DENYNONE. 
  4960.  
  4961. /* this will copy an open program */
  4962.  
  4963. #define INCL_NOPM
  4964. #define INCL_DOS
  4965. #include <os2.h>
  4966. #include <stdio.h>
  4967. #include <string.h>
  4968.  
  4969. void usage(void)
  4970. {
  4971.     printf("USAGE: CopyOpen <source file> <dest file>\n\n");
  4972.     printf("       This program,  unlike the normal copy and xcopy commands,\n");
  4973.     printf("       will copy an open file.\n");
  4974.     printf("NOTE:  Wildcards are not supported\n");
  4975. }
  4976.  
  4977. int cdecl main(int argc, char **argv)
  4978. {
  4979.     HFILE hf, hfOut;
  4980.     USHORT usAction, rc, bytesRead, bytesWriten ;
  4981.     static BYTE buf[4096];
  4982.     long total=0l;
  4983.     int error = FALSE;
  4984.  
  4985.     if(argc!=3){
  4986.         usage();
  4987.         return 1;
  4988.     }
  4989.     rc = DosOpen(strupr(argv[1]),
  4990.         &hf,
  4991.         &usAction,
  4992.         0L,
  4993.         FILE_NORMAL,
  4994.         FILE_OPEN,
  4995.         OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  4996.         0L);
  4997.     if(rc){
  4998.         printf("SYS%04u: Could not open %s for read.\n", rc, argv[1]);
  4999.         return 3;
  5000.     }
  5001.     rc = DosOpen(strupr(argv[2]),
  5002.         &hfOut,
  5003.         &usAction,
  5004.         0L,
  5005.         FILE_NORMAL,
  5006.         FILE_CREATE | FILE_TRUNCATE,
  5007.         OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE,
  5008.         0L);
  5009.     if(rc){
  5010.         printf("SYS%04u: Could not open %s for write.\n", rc, argv[2]);
  5011.         return 3;
  5012.     }
  5013.     else{
  5014.         do{
  5015.             rc = DosRead(hf, buf, sizeof(buf), &bytesRead);
  5016.             if(!rc){
  5017.                rc = DosWrite(hfOut, buf, bytesRead, &bytesWriten);
  5018.                if(!rc) total += bytesWriten;
  5019.             }
  5020.         }while(!rc &&
  5021.                sizeof(buf) == bytesRead &&
  5022.                bytesRead == bytesWriten);
  5023.         if(rc){
  5024.             printf("SYS%04u: while copying.\n", rc);
  5025.             error = TRUE;
  5026.         }
  5027.         if(bytesRead != bytesWriten){
  5028.             printf("Disk full?\n");
  5029.             error = TRUE;
  5030.         }
  5031.         DosClose(hf);
  5032.         if(!error)
  5033.             printf("%lu bytes copied.\n", total);
  5034.     }
  5035.     return( error? 3 : 0);
  5036. }
  5037.  
  5038. Credit:  Peter Fitzsimmons 
  5039.  
  5040.  
  5041. ΓòÉΓòÉΓòÉ 9.6. Can we use Vio in v2.0? Where are the docs for it? ΓòÉΓòÉΓòÉ
  5042.  
  5043. Yes; check cdrom.com for PRCP.ZIP. 
  5044.  
  5045.  
  5046. ΓòÉΓòÉΓòÉ 9.7. Can I redirect stdin and stdout in a child process? ΓòÉΓòÉΓòÉ
  5047.  
  5048. This is what I use to redirect stderr, stdout to a file from a program I start 
  5049. using DosStartSession. You could do the same type of thing using a pipe. 
  5050.  
  5051.     ULONG  ulAction;
  5052.     ULONG  ulNew;
  5053.     HFILE  hfFile, hfNewStdOut = -1, hfNewStdErr = -1,
  5054.            hfStdOut = 1, hfStdErr = 2;
  5055.  
  5056.     // Open output file
  5057.     DosOpen( szOutputFile, &hfFile, &ulAction, 1, 0,
  5058.              FILE_OPEN | FILE_CREATE,
  5059.              OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L );
  5060.     // Duplicate handles
  5061.     DosDupHandle( hfStdOut, phfNewStdOut );
  5062.     DosDupHandle( hfStdErr, phfNewStdErr );
  5063.     // Close existing handles for current process
  5064.     DosClose( hfStdOut );
  5065.     DosClose( hfStdErr );
  5066.     // Redirect existing handles to new file
  5067.     DosDupHandle( hfFile, &hfStdOut );
  5068.     DosDupHandle( hfFile, &hfStdErr );
  5069.     // Let started program inherit handles from parent
  5070.     stdata.InheritOpt = SSF_INHERITOPT_PARENT;
  5071.     // Start new session
  5072.     DosStartSession( &stdata, &ulSessionID, &pidSession );
  5073.     // Get back original handles
  5074.     DosDupHandle( hfNewStdOut, &hfStdOut );
  5075.     DosDupHandle( hfNewStdErr, &hfStdErr );
  5076.     // Close the duplicated handles - no longer needed
  5077.     DosClose( hfNewStdOut );
  5078.     DosClose( hfNewStdErr );
  5079.  
  5080. Credit:  Rick Fishman 
  5081.  
  5082.  
  5083. ΓòÉΓòÉΓòÉ 9.8. How do I use DosMon*() to stuff the kbd buf? ΓòÉΓòÉΓòÉ
  5084.  
  5085. Here's a mini app (all error handling, comments, etc. removed.) 
  5086.  
  5087. (also all this stuff to avoid compile warnings !!!!!). 
  5088.  
  5089. compile with: icc -Sm -Kabgioprx+ -Ss+ -W3 -Gs+ -Gf+ -O+ KEY.C
  5090. start with: detach key
  5091. stop with: F11 or CTRL-F10
  5092. test envir: OS/2 2.0GA+SP, C-Set++ CSD 22.
  5093. no other functionality.
  5094.  
  5095. orginal src part of my glorious DOS/OS2 1.x/OS2 2.0 keyboard roboter which 
  5096. inserts keys into the keyboard monitor queue controlled by an source file (mini 
  5097. language). 
  5098.  
  5099.    (C) Mario Semo 1777,1832,1967-92. 
  5100.  
  5101. ========= TOP OF FILE KEY.C ================ 
  5102.  
  5103. #define INCL_DOS
  5104. #define INCL_KBD
  5105. #define INCL_NOPM
  5106.  
  5107. #include<os2.h>
  5108. #include<stdio.h>
  5109. #include<conio.h>
  5110. #include<process.h>
  5111. #include<stdlib.h>
  5112. #include<string.h>
  5113.  
  5114. #define DosMonOpen  DOS16MONOPEN
  5115. #define DosMonClose DOS16MONCLOSE
  5116. #define DosMonReg   DOS16MONREG
  5117. #define DosMonRead  DOS16MONREAD
  5118. #define DosMonWrite DOS16MONWRITE
  5119.  
  5120. #define MONITOR_DEFAULT 0x0000
  5121. #define MONITOR_BEGIN   0x0001
  5122. #define MONITOR_END     0x0002
  5123.  
  5124. typedef SHANDLE HMONITOR;       /* hmon */
  5125. typedef HMONITOR *PHMONITOR;
  5126.  
  5127. #pragma pack(2)
  5128. typedef struct _MONIN {         /* mnin */
  5129.         USHORT cb;
  5130.         BYTE abReserved[18];
  5131.         BYTE abBuffer[108];
  5132. } MONIN;
  5133. typedef MONIN *PMONIN;
  5134.  
  5135. #pragma pack(2)
  5136. typedef struct _MONOUT {        /* mnout */
  5137.         USHORT cb;
  5138.         UCHAR buffer[18];
  5139.         BYTE abBuf[108];
  5140. } MONOUT;
  5141. typedef MONOUT *PMONOUT;
  5142.  
  5143. APIRET16 APIENTRY16 DosMonOpen(PSZ pszDevName, PHMONITOR phmon);
  5144. APIRET16 APIENTRY16 DosMonClose(HMONITOR hmon);
  5145. APIRET16 APIENTRY16 DosMonReg(HMONITOR hmon, PBYTE pbInBuf,
  5146.              PBYTE pbOutBuf, USHORT fPosition, USHORT usIndex);
  5147. APIRET16 APIENTRY16 DosMonRead(PBYTE pbInBuf, USHORT fWait,
  5148.                                PBYTE pbDataBuf,
  5149.                                PUSHORT pcbData);
  5150. APIRET16 APIENTRY16 DosMonWrite(PBYTE pbOutBuf, PBYTE pbDataBuf,
  5151.                                 USHORT cbData);
  5152.  
  5153. #define DosGetInfoSeg    DOS16GETINFOSEG
  5154. APIRET16 APIENTRY16 DosGetInfoSeg(PSEL pselGlobal, PSEL pselLocal);
  5155.  
  5156. #pragma pack(2)
  5157. typedef struct _GINFOSEG { /* gis */
  5158.         ULONG   time; ULONG   msecs; UCHAR   hour;
  5159.         UCHAR   minutes; UCHAR   seconds; UCHAR   hundredths;
  5160.         USHORT  timezone; USHORT cusecTimerInterval; UCHAR   day;
  5161.         UCHAR   month; USHORT  year; UCHAR   weekday;
  5162.         UCHAR   uchMajorVersion; UCHAR uchMinorVersion;
  5163.         UCHAR   chRevisionLetter; UCHAR   sgCurrent;
  5164.         UCHAR   sgMax; UCHAR   cHugeShift;
  5165.         UCHAR   fProtectModeOnly; USHORT pidForeground;
  5166.         UCHAR   fDynamicSched; UCHAR   csecMaxWait;
  5167.         USHORT  cmsecMinSlice; USHORT  cmsecMaxSlice;
  5168.         USHORT  bootdrive; UCHAR   amecRAS[32];
  5169.         UCHAR   csgWindowableVioMax; UCHAR   csgPMMax;
  5170. } GINFOSEG;
  5171. typedef GINFOSEG *PGINFOSEG;
  5172.  
  5173. static PGINFOSEG gdt;
  5174.  
  5175. #define MAKEPGINFOSEG(sel)  ((PGINFOSEG)MAKEP(sel, 0))
  5176. #define MAKEPLINFOSEG(sel)  ((PLINFOSEG)MAKEP(sel, 0))
  5177.  
  5178. #pragma pack(2)
  5179. typedef struct _keypacket
  5180.   {
  5181.    USHORT     mnflags;
  5182.    KBDKEYINFO cp;
  5183.    USHORT     ddflags;
  5184.   } KEYPACKET;
  5185.  
  5186.  
  5187. #define RELEASE     0x40
  5188. #define CTL_F10_KEY 103
  5189. #define F11_KEY     133
  5190.  
  5191. #pragma stack16(8192)
  5192. #pragma seg16(HKBD)
  5193. #pragma seg16(MONIN)
  5194. #pragma seg16(MONOUT)
  5195. #pragma seg16(KEYPACKET)
  5196.  
  5197. static HKBD KBDHandle = (HKBD)0;
  5198. static PGINFOSEG _Seg16 gdt;
  5199. static MONIN monInbuf = {0};
  5200. static MONOUT monOutbuf = {0};
  5201. static HEV hevThreadDone = (HEV)0;
  5202.  
  5203. static void _System keyboard_monitor(ULONG Dummy);
  5204.  
  5205. int main(int argc, char *argv[], char *envp[])
  5206. {
  5207.  SEL gdt_descriptor, ldt_descriptor;
  5208.  PID pidKeybrd;
  5209.  
  5210.  monInbuf.cb  = sizeof(MONIN);
  5211.  monOutbuf.cb = sizeof(MONOUT);
  5212.  
  5213.  DosGetInfoSeg(&gdt_descriptor, &ldt_descriptor);
  5214.  
  5215.  gdt = MAKEPGINFOSEG(gdt_descriptor);
  5216.  
  5217.  DosMonOpen ( "KBD$", &KBDHandle );
  5218.  
  5219.  DosCreateEventSem(NULL, &hevThreadDone,0,FALSE);
  5220.  
  5221.  if (DosCreateThread(&pidKeybrd, &keyboard_monitor, 0L, 2L, 12000L))
  5222.          DosExit(EXIT_PROCESS,0);
  5223.  
  5224.  DosWaitEventSem(hevThreadDone, (ULONG)SEM_INDEFINITE_WAIT);
  5225.  DosMonClose(KBDHandle);
  5226.  
  5227.  DosBeep(100,100);
  5228.  
  5229.  DosExit(EXIT_PROCESS,0);
  5230.  return(0);
  5231. }
  5232.  
  5233.  
  5234. static void _System keyboard_monitor(ULONG Dummy)
  5235. {
  5236.  KEYPACKET keybuff;
  5237.  USHORT count;
  5238.  
  5239.  DosSetPrty(PRTYS_THREAD, PRTYC_TIMECRITICAL,0, 0);
  5240.  
  5241.  DosMonReg( KBDHandle, (PBYTE)&monInbuf, (PBYTE)&monOutbuf,
  5242.             MONITOR_BEGIN, gdt->sgCurrent);
  5243.  
  5244.  DosSetPrty(PRTYS_THREAD, PRTYC_REGULAR,0, 0);
  5245.  
  5246.  for(keybuff.cp.chChar = 0; ; )
  5247.    {
  5248.     count = sizeof(keybuff);
  5249.     DosMonRead( (PBYTE)&monInbuf, IO_WAIT, (PBYTE)&keybuff, &count);
  5250.     if (!(keybuff.ddflags & RELEASE))
  5251.        {
  5252.         if(keybuff.cp.chChar == 0)
  5253.           {
  5254.            switch (keybuff.cp.chScan)
  5255.              {
  5256.               case CTL_F10_KEY   :
  5257.               case F11_KEY       :
  5258.                  DosPostEventSem(hevThreadDone);
  5259.                  DosExit(EXIT_THREAD,0);
  5260.                  break;
  5261.              }
  5262.           }
  5263.        }
  5264.     DosMonWrite((PBYTE)&monOutbuf,(PBYTE)&keybuff,count);
  5265.    }
  5266. }
  5267.  
  5268. Credit:  Mario Semo 
  5269.  
  5270.  
  5271. ΓòÉΓòÉΓòÉ 9.9. How do I determine what file system a drive uses? ΓòÉΓòÉΓòÉ
  5272.  
  5273. 16 bit:  DosQFsInfo().
  5274. 32 but:  DosQueryFSInfo()
  5275.  
  5276. The folling little 16 bit program produces the following output on my computer: 
  5277.  
  5278.  LOCAL  C:  FAT
  5279.  LOCAL  D:  HPFS
  5280.  LOCAL  E:  HPFS
  5281.  LOCAL  F:  FAT
  5282.  REMOTE P:  LAN   \\SERV1\C$
  5283.  REMOTE Q:  LAN   \\SERV1\D$
  5284.  REMOTE R:  LAN   \\SERV1\E$
  5285.  
  5286. Code.... 
  5287.  
  5288.  /* qdisk.c */
  5289.  #define INCL_NOPM
  5290.  #define INCL_DOS
  5291.  #include <os2.h>
  5292.  #include <stdio.h>
  5293.  #include <stdlib.h>
  5294.  
  5295.  
  5296.  void errorRC(USHORT rc)
  5297.  {
  5298.      char msg[256];
  5299.      USHORT bc;
  5300.      if(0 != (rc=DosGetMessage(NULL, 0, msg, sizeof(msg), rc,
  5301.                                "OSO001.MSG", &bc))) {
  5302.          printf("SYS%04u: Unable to access OSO001.MSG\n", rc);
  5303.      }
  5304.      else DosWrite(2, msg, bc, &bc);
  5305.  }
  5306.  
  5307.  void qdisk(char drv)
  5308.  {
  5309.      USHORT rc, len;
  5310.      char dev[3];
  5311.      void *buf;
  5312.      char *p;
  5313.  
  5314.      if(drv < 'C')
  5315.          return;
  5316.      sprintf(dev, "%c:", drv);
  5317.      buf = malloc(2048);
  5318.      len = 2048;
  5319.      rc = DosQFSAttach(dev, 0, FSAIL_QUERYNAME, buf, &len, 0L);
  5320.      if(rc){
  5321.          errorRC(rc);
  5322.          return;
  5323.      }
  5324.      switch((*(PUSHORT)buf)){
  5325.          case FSAT_CHARDEV  : printf("CHAR   "); break;
  5326.          case FSAT_PSEUDODEV: printf("DEV    "); break;
  5327.          case FSAT_LOCALDRV : printf("LOCAL  "); break;
  5328.          case FSAT_REMOTEDRV: printf("REMOTE "); break;
  5329.          default: printf("Unknown "); break;
  5330.      }
  5331.      p = buf;
  5332.      p += sizeof(USHORT);    /* itype */
  5333.      printf("%-3s ", p+sizeof(USHORT));
  5334.      p += (sizeof(USHORT) + (*(USHORT *)p) + 1);    /* cbName */
  5335.      printf("%-8s ", p+sizeof(USHORT));
  5336.      p += (sizeof(USHORT) + (*(USHORT *)p) + 1);    /* cbFSDName */
  5337.      if((*(USHORT *)p))                             /* cbFSAData */
  5338.          printf("%s", p+sizeof(USHORT));
  5339.      printf("\n");
  5340.      free(buf);
  5341.  }
  5342.  
  5343.  void cdecl main(void)
  5344.  {
  5345.      char drv;
  5346.      USHORT usDisk;
  5347.      ULONG ulDrives;
  5348.      DosQCurDisk(&usDisk, &ulDrives); /* gets current drive */
  5349.      for (drv = 'A'; drv <= 'Z'; drv++) {
  5350.          if (ulDrives & 1)              /* if the drive bit is set, */
  5351.              qdisk(drv);
  5352.          ulDrives >>= 1;
  5353.      }
  5354.  }
  5355.  
  5356. ps: DosQSysInfo() will return the max path length that your version of OS/2 
  5357. supports.  But since this API is specific to OS/2,  and not to a particular 
  5358. drive,  it does not answer your original question. 
  5359.  
  5360. Credit: Peter Fitzsimmons 
  5361.  
  5362.  
  5363. ΓòÉΓòÉΓòÉ 9.10. How do I get the error message from a DOS API call? ΓòÉΓòÉΓòÉ
  5364.  
  5365. For DOSAPI calls, you can issue a DosGetMessage as follows: 
  5366.  
  5367.    RC = DosXXXX(...);
  5368.    DosGetMessage(NULL,0,Msg,sizeof(Msg),RC,"OSO001.MSG",&Msg_Length);
  5369.  
  5370. Credit:  Ken Kahn 
  5371.  
  5372.  
  5373. ΓòÉΓòÉΓòÉ 9.11. How do I set an exception handler? ΓòÉΓòÉΓòÉ
  5374.  
  5375. /*
  5376.  * Simple example of an exception handler
  5377.  */
  5378.  
  5379. #define INCL_DOS
  5380. #include <os2.h>
  5381. #include <setjmp.h>
  5382. #include <stdio.h>
  5383. #include <string.h>
  5384.  
  5385. extern int main(void);
  5386.  
  5387.  /*
  5388.  * Exception registration record.  Stored on stack, with first
  5389.  * pointer to next registeration record, second pointer to
  5390.  * exception handler, and the rest defined by the author of
  5391.  * the exception handler.
  5392.  */
  5393.  
  5394. typedef struct {
  5395.   struct _EXCEPTIONREGISTRATIONRECORD * volatile prev_structure;
  5396.    _ERR * volatile ExceptionHandler;
  5397.    jmp_buf env;
  5398. } MYEXCEPTIONREGISTRATIONRECORD, *PMYEXCEPTIONREGISTRATIONRECORD;
  5399.  
  5400. /*
  5401.  * Exception handler that returns traps via longjmp().
  5402.  */
  5403.  
  5404. extern ULONG APIENTRY MyExceptionHandler
  5405.     (PEXCEPTIONREPORTRECORD pReportRecord,
  5406.     PEXCEPTIONREGISTRATIONRECORD pRegRecord,
  5407.     PCONTEXTRECORD pContextRecord, PVOID pReserved)
  5408. {
  5409.   ULONG rc = XCPT_CONTINUE_SEARCH;
  5410.  
  5411.   if (pReportRecord->ExceptionNum == XCPT_ACCESS_VIOLATION)
  5412.     longjmp(((PMYEXCEPTIONREGISTRATIONRECORD) pRegRecord)->env, -1);
  5413.  
  5414.   /*
  5415.    * If we return to here then we could not handle the exception.
  5416.    */
  5417.  
  5418.   return rc;
  5419. }
  5420.  
  5421. extern BOOL Trapper(PSZ psz)
  5422. {
  5423.   MYEXCEPTIONREGISTRATIONRECORD myExceptionRegRecord;
  5424.  
  5425.   /*
  5426.    * Insert my exception handler into the chain.
  5427.    */
  5428.  
  5429.   myExceptionRegRecord.prev_structure = NULL;
  5430.   myExceptionRegRecord.ExceptionHandler = MyExceptionHandler;
  5431.   DosSetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD) &myExceptionRegRecord);
  5432.  
  5433.   if (setjmp(myExceptionRegRecord.env))
  5434.     goto OnException;
  5435.  
  5436.   /*
  5437.    * Now go about my business in safety.
  5438.    */
  5439.  
  5440.   if (strlen(psz))
  5441.     printf("Trapper says okay to '%s'\n", psz);
  5442.   else
  5443.     printf("Trapper says it is empty\n");
  5444.  
  5445.   /*
  5446.    * I'm done, so unchain my exception handler.
  5447.    */
  5448.  
  5449.   DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&myExceptionRegRecord)
  5450.  
  5451.   return TRUE;
  5452.  
  5453.   /*
  5454.    * The code below is only executed if a trap occurs.
  5455.    */
  5456.  
  5457. OnException:
  5458.   printf("Trapper says 'ouch!'\n");
  5459.  
  5460.   DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&myExceptionRegRecord)
  5461.  
  5462.   return FALSE;
  5463. }
  5464.  
  5465. extern int main()
  5466. {
  5467.   Trapper("Hello");
  5468.   Trapper(NULL);
  5469.   Trapper("");
  5470.   Trapper((PSZ) 42);
  5471.   Trapper("Goodbye");
  5472.  
  5473.   return 0;
  5474. }
  5475.  
  5476. Credit:  Dan Kehn 
  5477.  
  5478.  
  5479. ΓòÉΓòÉΓòÉ 9.12. How can I determine a diskette format and if a disk is in a drive? ΓòÉΓòÉΓòÉ
  5480.  
  5481. Let's have a snippet from one of my functions: 
  5482.  
  5483. The 'ifdef M_I386's mean CSet/2 
  5484.  
  5485. --- snip --- 
  5486.  
  5487. EXPORT int GetFileSysAttach ( char cDrv, PVOID pInfo, UnsInt cbInfo )
  5488. {
  5489. CHAR szFileSys [4];
  5490.  
  5491.   szFileSys [0] = (CHAR) toupper ( cDrv );
  5492.   szFileSys [1] = ':';
  5493.   szFileSys [2] = '\0';
  5494.  
  5495.   DosError ( EXCEPTION_DISABLE );
  5496.  
  5497. #ifdef M_I386
  5498.   Errno = DosQueryFSAttach ( szFileSys, 0, FSAIL_QUERYNAME, pInfo, &cbInfo );
  5499. #else
  5500.   Errno = DosQFSAttach ( szFileSys, 0, FSAIL_QUERYNAME, pInfo, &cbInfo, 0L );
  5501. #endif
  5502.  
  5503.   DosError ( EXCEPTION_ENABLE );
  5504.   return Errno ? -1 : 0;
  5505. }
  5506.  
  5507.  
  5508. EXPORT    int    GetFileSysInfo ( PSZ pszFileSys, PFSysInfo pfsi )
  5509. {
  5510. USHORT    idDrv;
  5511. FSALLOCATE fsal;
  5512. FSINFO    fsinfo;
  5513. #ifdef M_I386
  5514. PFSQBUFFER2 fsq = NULL;
  5515. #else
  5516. PFSQBUFFER  fsq = NULL;
  5517. PUSHORT     pus;
  5518. #endif
  5519. CHAR    hbuf [L_FILENAME];
  5520. PCHAR   pch;
  5521. #ifndef _MT
  5522. BOOL    fProt = ProtectedMode ();
  5523. #else
  5524. #define fProt TRUE
  5525. #endif
  5526.  
  5527.   idDrv = tolower ( *pszFileSys ) - ('a' - 1);
  5528.  
  5529.   DosError ( EXCEPTION_DISABLE );
  5530.  
  5531.   if ( ! (Errno = DosQFSInfo ( idDrv, 1, (PBYTE) &fsal, sizeof ( fsal ) )) )
  5532.     Errno = DosQFSInfo ( idDrv, 2, (PBYTE) &fsinfo, sizeof ( fsinfo ) );
  5533.  
  5534.   DosError ( EXCEPTION_ENABLE );
  5535.  
  5536.   if ( Errno )
  5537.   {
  5538.     if ( Errno == ERROR_NO_VOLUME_LABEL )
  5539.       memset ( &fsinfo, 0, sizeof (fsinfo) );
  5540.     else
  5541.       return -1; // No disk inserted
  5542.   }
  5543.  
  5544.   if ( fProt )
  5545.   {
  5546.     if ( GetFileSysAttach ( (CHAR) (idDrv + 'a' - 1), hbuf, L_FILENAME ) )
  5547.       return -1;
  5548.  
  5549. #ifdef M_I386
  5550.     fsq = (PFSQBUFFER2) hbuf;
  5551. #else
  5552.     fsq = (PFSQBUFFER) hbuf;
  5553. #endif
  5554.   }
  5555.  
  5556.   DosError ( EXCEPTION_ENABLE );
  5557.  
  5558.   ...
  5559.  
  5560. --- snap --- 
  5561.  
  5562. I think it's more than you want, the fsal-struct contains the size information, 
  5563. but I think if you want to retrieve ALL information about a logical drive 
  5564. that's what you need. 
  5565.  
  5566. Credit:  Rainer Prem 
  5567.  
  5568.  
  5569. ΓòÉΓòÉΓòÉ 9.13. What do all those keywords mean when making a DLL? ΓòÉΓòÉΓòÉ
  5570.  
  5571. Okay, with the help of some of my peers, I've solved the mystery surrounding 
  5572. the seemingly redundant SINGLE/MULTIPLE and SHARED/NONSHARED attributes. 
  5573.  
  5574. First, some prep up work... 
  5575.  
  5576. Every DLL needs and gets a data segment ("automatic data segment"). It is the 
  5577. place where the DLL stores all its STATIC data--basically the data declared in 
  5578. the DLL module but declared outside any function AND (I venture) variables 
  5579. declared STATIC within a DLL function as well. The STACK is NOT!! part of a 
  5580. DLL's automatic data segment (thoug it seems to be for an EXE). The stack that 
  5581. is used when 'running' a DLL function is that of the calling thread. 
  5582.  
  5583. Now here's the clincher... 
  5584.  
  5585. DLLs CAN ALSO HAVE ADDITIONAL DATA SEGMENTS!! (as can EXEs, I imagine) 
  5586.  
  5587. Bingo! Now we understand why there are two different sets of 
  5588. attributes--specifically, NONE/SINGLE/MULTIPLE and SHARED/NONSHARED. Though 
  5589. they basically do the same thing, they APPLY to different things. 
  5590.  
  5591. NONE/SINGLE/MULTIPLE 
  5592.           applies to the one and only default data segment. This is the data 
  5593.           segment that is "automatically" created for your DLL (or EXE). I 
  5594.           imagine that for 90% of the DLLs written, this is the only type of 
  5595.           data segment that exists. Whether or not this data segment is shared 
  5596.           or whether a private copy is created for each linking application is 
  5597.           A DIRECT FUNCTION OF THIS ATTRIBUTE--'SINGLE'=it's shared, 
  5598.           'MULTIPLE'=everyone get's his own copy. 
  5599.  
  5600. SHARED/NONSHARED 
  5601.           This SETS THE DEFAULT!! FOR ALL DATA SEGMENTS other than the 
  5602.           "automatic" data segment. DEFAULT is the key word, because you can 
  5603.           specify, through the SEGMENTS statement, the characteristics of these 
  5604.           additional segments on an individual basis (which in all certainty, 
  5605.           override this value.) 
  5606.  
  5607. So...to answer my own question 
  5608.  
  5609. >could {someone} explain what the following statements would
  5610. >produce:
  5611. >
  5612. >        DATA MULTIPLE SHARED
  5613.  
  5614. Every application which links to the DLL will have it's own private copy of the 
  5615. automatic data segment. If the DLL has no additional data segments, the SHARED 
  5616. keyword is meaningless and can be omitted. If there are additional data 
  5617. segments, only one copy of each will exist and they will be shared by all 
  5618. applications (unless a SEGMENTS statement follows which overrides this default 
  5619. for a specific segment) 
  5620.  
  5621. >        or
  5622. >        DATA SINGLE NONSHARED
  5623.  
  5624. Every application which links to the DLL will share a single automatic data 
  5625. segment (hence, each app that affects the DLL STATIC data will affect it for 
  5626. all apps). If there are no additional data segments, the NONSHARED keyword is 
  5627. meaningless and can be omitted. If there are, a private copy will be created 
  5628. for each app (unless overriden by a SEGMENTS statement). 
  5629.  
  5630. Note that in the absence of BOTH a SINGLE/MUTLIPLE and SHARED/NONSHARED 
  5631. keyword, the default is for ALL data segments (automatic and additional ones) 
  5632. to be shared (i.e., only one copy). In the absence of one OR the other, but not 
  5633. both, the property of ALL data segments are mandated by the single keyword. In 
  5634. other words, 
  5635.  
  5636. DATA SINGLE
  5637.  and
  5638. DATA SHARED
  5639.  
  5640. do the same exact thing. 
  5641.  
  5642. Credit:  John Cortell 
  5643.  
  5644.  
  5645. ΓòÉΓòÉΓòÉ 9.14. Where can I find serial port sample code? ΓòÉΓòÉΓòÉ
  5646.  
  5647. Q)  Does anyone have any C sample code showing how to use the serial port under 
  5648. OS/2 using DosOpen() and DosDevIoCtl()? 
  5649.  
  5650. A) As a matter of fact, yes.  :-) 
  5651.  
  5652. -=-= extracted from a silly & specialized program =-=-=-=-==-=-=
  5653.  
  5654. /* dtp.c -- D-dial Terminal Program: the first hack */
  5655.  
  5656. //-- an annoying detail
  5657.  
  5658. #define INCL_BASE
  5659. #define INCL_DOSDEVIOCTL  /* docs lie, this is NOT included by BASE */
  5660. #include <os2.h>
  5661.  
  5662. //-- initialization (in main() as written)
  5663.  
  5664.     HFILE portFd;
  5665.     ULONG action;
  5666.  
  5667.     if (DosOpen("COM1", &portFd, &action, 0, FILE_NORMAL, FILE_OPEN,
  5668.       OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE, 0) != 0) {
  5669.         fprintf(stderr, "Open of COM1 failed\n");
  5670.         goto error0;
  5671.     }
  5672.  
  5673.     {    DCBINFO di;
  5674.         ULONG dummy;
  5675.  
  5676.         dummy = sizeof(di);
  5677.         if (DosDevIOCtl(portFd, IOCTL_ASYNC, ASYNC_GETDCBINFO, 0, 0, 0,
  5678.                         &di, sizeof(di), &dummy) != 0)
  5679.             fprintf(stderr, "DosDevIOCtl failed\n");
  5680.         else {
  5681.             fprintf(stderr, "Timeouts: read = %u, write = %u\n",
  5682.                     di.usWriteTimeout, di.usReadTimeout);
  5683.             fprintf(stderr, "Flag bytes: %02x, %02x, %02x\n",
  5684.                     di.fbCtlHndShake, di.fbFlowReplace, di.fbTimeout);
  5685.         }
  5686.         di.fbTimeout = (di.fbTimeout & ~(3 << 1)) | (2 << 1);
  5687.                                           /* rcv = wait-for-something */
  5688.         di.usReadTimeout = 250;
  5689.         dummy = sizeof(di);
  5690.         if (DosDevIOCtl(portFd, IOCTL_ASYNC, ASYNC_SETDCBINFO,
  5691.                         &di, sizeof(di), &dummy, 0, 0, 0) != 0)
  5692.             fprintf(stderr, "DosDevIOCtl failed to set parameters!\a\n");
  5693.     }
  5694.  
  5695.     if (initSerialOutput(portFd) != 0)
  5696.         goto error1;
  5697.  
  5698. //-- the "running" variable is sort of a relic, I think
  5699.  
  5700.     running = 1;
  5701.     if (_beginthread(serialInputThread, 0, 8192, (void *)portFd) < 0) {
  5702.         fprintf(stderr, "can't start serial input thread\n");
  5703.         goto error2;
  5704.     }
  5705.  
  5706.     if (_beginthread(serialOutputThread, 0, 8192, (void *)portFd) < 0) {
  5707.         fprintf(stderr, "can't start serial output thread\n");
  5708.         goto error2;
  5709.     }
  5710.  
  5711. //-- wrapup code
  5712.  
  5713.     shutdownSerialOutput();
  5714.     DosClose(portFd);
  5715.  
  5716. //-- the rest of this lives outside of main()...
  5717.  
  5718. //-- input side: gory details omitted
  5719.  
  5720. //-- the port has been setup in "wait for something" mode, so we can request
  5721. //-- more than one character at a time without blocking until the buffer is
  5722. //-- full.  At least, I *think* that's working now: this is used with 300 baud
  5723. //-- systems, so it's hard to tell <g>.  At least it isn't blocking until the
  5724. //-- buffer is filled...
  5725.  
  5726. /*  serialInputThread -- reads port, writes to text window
  5727. *
  5728. *   arg is the port's handle for reading
  5729. */
  5730. void serialInputThread(void *arg)
  5731. {
  5732.     HFILE inFd = (long)arg;
  5733.     FILE *logFile;
  5734.     UCHAR buf[10];
  5735.  
  5736.     ParserState ps = {0};
  5737.  
  5738.     logFile = fopen("dtp.log", "ab");
  5739.  
  5740.     for ( ; ; )
  5741.     {
  5742.         ULONG n;
  5743.         if (DosRead(inFd, buf, 10, &n) == 0)
  5744.         {
  5745.             ULONG i;
  5746.             for (i = 0; i <n; ++i)
  5747.             {
  5748.                 if (logFile != 0)
  5749.                     putc(buf[i], logFile);
  5750.                 if (runParser(&ps, buf[i]) != 0)
  5751.                     postChar(buf[i]);
  5752.             }
  5753.         }
  5754.     }
  5755. }
  5756.  
  5757. /* output side: I rather like this arrangement using queues
  5758.    except that I'd prefer an anonymous queue.
  5759.    For this, having the queue named in the
  5760.    filesystem's name space is at best a minor annoyance. */
  5761.  
  5762. /* * * *    SerialOutput subsystem
  5763. */
  5764.  
  5765. #define MAX_CHUNK_SIZE 50
  5766.  
  5767. typedef struct
  5768. {
  5769.     USHORT nUsed;
  5770.     UCHAR buf[MAX_CHUNK_SIZE];
  5771. } SO_CHUNK;
  5772.  
  5773. #define NUM_SO_CHUNKS 6
  5774.  
  5775.  
  5776. HQUEUE soQueue, freeQueue;
  5777.  
  5778.  
  5779. int initSerialOutput (HFILE outFd)
  5780. {
  5781.     (void) outFd;     /* reserved for more general version */
  5782.  
  5783.     if (DosCreateQueue
  5784.        (&soQueue, QUE_FIFO, "\\queues\\dtp\\soQueue") != 0)
  5785.     {
  5786.         fprintf(stderr, "Failed to create serial output queue\n");
  5787.         goto error0;
  5788.     }
  5789.     if (DosCreateQueue
  5790.        (&freeQueue, QUE_FIFO, "\\queues\\dtp\\freeQueue") != 0)
  5791.     {
  5792.         fprintf(stderr, "Failed to create serial free queue\n");
  5793.         goto error1;
  5794.     }
  5795.     {   SO_CHUNK *p = malloc(sizeof(SO_CHUNK) * NUM_SO_CHUNKS);
  5796.         int i;
  5797.         if (p == 0)
  5798.         {
  5799.             fprintf(stderr,
  5800.             "Failed to allocate memory for serial chunks\n");
  5801.             goto error1;
  5802.         }
  5803.         for (i = NUM_SO_CHUNKS; 0 < i; --i)
  5804.             if (DosWriteQueue(freeQueue, 0, sizeof(SO_CHUNK), p++, 0)
  5805.             != 0)
  5806.             {
  5807.                 fprintf(stderr, "Failed to initialize free queue\n");
  5808.                 goto error1;
  5809.             }
  5810.     }
  5811.  
  5812.     return 0;
  5813.  
  5814. error1:
  5815.     DosCloseQueue(soQueue);
  5816. error0:
  5817.     return -1;
  5818. }
  5819.  
  5820.  
  5821. void shutdownSerialOutput(void)
  5822. {
  5823.     DosCloseQueue(freeQueue);
  5824.     DosCloseQueue(soQueue);
  5825. }
  5826.  
  5827.  
  5828. void writeSerial(UCHAR const *buf, USHORT n)
  5829. {
  5830.  
  5831.     while (0 < n)
  5832.     {
  5833.         REQUESTDATA rd;
  5834.         ULONG dataLength;
  5835.         PVOID data;
  5836.         BYTE priority;
  5837.  
  5838.         if (DosReadQueue(freeQueue, &rd, &dataLength, &data,
  5839.                          0, DCWW_WAIT, &priority, 0) == 0)
  5840.         {
  5841.             SO_CHUNK *sc = data;
  5842.             USHORT m = MAX_CHUNK_SIZE;
  5843.             if (n < m)
  5844.                 m = n;
  5845.             memcpy(sc->buf, buf, m);
  5846.             sc->nUsed = m;
  5847.             DosWriteQueue(soQueue, 0, sizeof(SO_CHUNK), sc, 0);
  5848.             buf += m;
  5849.             n -= m;
  5850.         }
  5851.     }
  5852. }
  5853.  
  5854.  
  5855. void writeSerialString(UCHAR const *buf)
  5856. {
  5857.     writeSerial(buf, strlen(buf));
  5858. }
  5859.  
  5860.  
  5861. void serialOutputThread(void *arg)
  5862. {
  5863.     HFILE outFd = (long)arg;
  5864.     REQUESTDATA rd;
  5865.     ULONG dataLength;
  5866.     PVOID data;
  5867.     BYTE priority;
  5868.  
  5869.     for ( ; ; )
  5870.     {
  5871.         if (DosReadQueue(soQueue, &rd, &dataLength, &data,
  5872.                          0, DCWW_WAIT, &priority, 0) == 0)
  5873.         {
  5874.             if (rd.ulData == 0) {     /* simple data block */
  5875.                 ULONG dummy;
  5876.                 SO_CHUNK *sc = data;
  5877.                 DosWrite(outFd, sc->buf, sc->nUsed, &dummy);
  5878.                 DosWriteQueue(freeQueue, 0, sizeof(SO_CHUNK), sc, 0);
  5879.             }
  5880.             else
  5881.                 ;  /* anything else is a test, ignore it */
  5882.         }
  5883.     }
  5884. }
  5885.  
  5886. The intention was that control messages could be posted to the queue using null 
  5887. data packets (passing the actual message in the REQUESTDATA.ulData field); 
  5888. these would allow for controlling the port's baud rate and other settings. 
  5889. This seems to work under 2.0, and even appears to be intended to work (Deitel & 
  5890. Kogan's description), but I haven't done anything with it yet, as you can see. 
  5891. Haven't needed the facility yet... 
  5892.  
  5893. Credit:  Martin Maney 
  5894.  
  5895.  
  5896. ΓòÉΓòÉΓòÉ 9.15. How do I disable <Ctrl><Alt><Del>? ΓòÉΓòÉΓòÉ
  5897.  
  5898. You need to do a DosDevIOCtl with Category 4, Function 56. Use a 0xFFFF for the 
  5899. Hot Key ID.  Set the other values to 0. This will toggle <Ctrl><Alt><Del> and 
  5900. <Ctrl><Esc> and <Alt><Esc> on then off on the next call. Note that this does a 
  5901. little more than what you want since it also disables <Ctrl><Esc> and 
  5902. <Alt><Esc> so you may run into problems getting around your different sessions 
  5903. when you've got it disabled. Other than this there is NO WAY to disable 
  5904. <Ctrl><Alt><Del> under OS/2 and believe me, people have tried! 
  5905.  
  5906. Credit:  Mike Brown 
  5907.  
  5908.  
  5909. ΓòÉΓòÉΓòÉ 9.16. Why doesn't printf() produce output when I expect it to? ΓòÉΓòÉΓòÉ
  5910.  
  5911. For historical reasons, most Unix C libraries' stdio default to using line 
  5912. buffered streams, whereas most DOS and OS/2 C libraries' stdio default to using 
  5913. fully buffered streams.  ANSI C species that standard output should be line 
  5914. buffered when connected to an interactive device, but not all libraries are 
  5915. ANSI compliant.  You can control the buffering algorithm used for a particular 
  5916. stream with the setvbuf() function. 
  5917.  
  5918. If you didn't understand that paragraph, read on. 
  5919.  
  5920. printf() is part of the Standard I/O (stdio) library, which uses buffered 
  5921. streams for file IO.  ANSI C specifies three algorithms for deciding when to 
  5922. flush the buffer (i.e. when to print buffered data to the file): 
  5923.  
  5924. o not buffered.  Data is flushed to the file as soon as possible, usually 
  5925.   immediately after being received. 
  5926. o line buffered.  Data is flushed to the file when a newline is received (and 
  5927.   the newline is also flushed). 
  5928. o fully buffered.  Data is flushed to the file when the buffer is full. 
  5929.  
  5930. Buffered data is always flushed when the stream is closed or when fflush() is 
  5931. called.  Since standard output is flushed when main() exits, all data printed 
  5932. with printf() will appear at that time, if it has not already.  However, ANSI C 
  5933. does not require that a stream be flushed when scanf() is called on it. 
  5934. Therefore, if you print to a fully buffered stream and then request input on 
  5935. it, it is likely that the input will be read before the printed data appears. 
  5936.  
  5937. You can control the buffering algorithm used for a particular stream with the 
  5938. setvbuf() function.  For example, the statement setvbuf(stdout, NULL, _IOLBF, 
  5939. BUFSIZ) sets standard output to be line-buffered, which is what most Unix 
  5940. programmers expect.  Any decent C reference will cover all of this material. 
  5941.  
  5942. [Colin Jensen...] 
  5943.  
  5944. After reading one too many bug reports about this phenomena, the gcc/2 
  5945. maintainer changed its stdout to not-buffered whenever stdout is interactive. 
  5946. When stdout is sent to a pipe or file, stdout is still fully-buffered. 
  5947.  
  5948.  
  5949. ΓòÉΓòÉΓòÉ 9.17. How do I write an OS/2 device driver? ΓòÉΓòÉΓòÉ
  5950.  
  5951. The preferred method is to buy the OS/2 device driver kit (DDK) from IBM.  It 
  5952. contains samples for display, printer, SCSI, and other drivers. You can develop 
  5953. kernel and PM drivers.    NOTE:  The kernel debugger comes with the IBM Toolkit, 
  5954. sold separately. 
  5955.  
  5956. There's a book called Writing OS/2 2.0 Device Drivers in C from 
  5957. Van Nostrand-Reinhold and also IBM's flood of printed material. 
  5958.  
  5959.  
  5960. Related Information:
  5961.  
  5962. What are good reference books for programming in OS/2 and PM?
  5963.  
  5964.  
  5965. ΓòÉΓòÉΓòÉ 9.18. How do I change the master environment? ΓòÉΓòÉΓòÉ
  5966.  
  5967. Quick and simple answer: you don't. 
  5968.  
  5969. In OS/2 it is literally impossible for you to change the master environment 
  5970. from one of your programs.    To be able to do so would fatally disrupt the 
  5971. programming paradigm that has existed for ages:  Your program does not alter 
  5972. the master environment. Your program is the slave, not the master.  Therefore, 
  5973. no capability was built into OS/2 to facilitate this. 
  5974.  
  5975. There is, however, a kludge. 
  5976.  
  5977. As you know, a .CMD file can alter the master environment.  This is the nature 
  5978. of batch files (ok, so I'm a MS-DOG dinosaur and still call them batch files 
  5979. instead of command files or scripts).  Therefore, you can place a sequence of 
  5980. commands in the batch file that will take your program's output and alter the 
  5981. environment of your current shell. 
  5982.  
  5983. That's as close as you are gonna get to the master environment.  You can always 
  5984. create your own sort of environment variables, in the form of shared memory or 
  5985. named pipes. 
  5986.  
  5987.  
  5988. ΓòÉΓòÉΓòÉ 9.19. What is the best way to communicate between processes? ΓòÉΓòÉΓòÉ
  5989.  
  5990. There is more than one way - and you get to decide which is right for you! 
  5991.  
  5992. Shared Memory 
  5993.  
  5994. Shared memory is pretty self-explanatory.  It is a memory segment that is 
  5995. allocated by one program, and then made available to other programs. When all 
  5996. the programs are done with it, then it is disposed of.  You can name shared 
  5997. memory.  So if you want two programs to communicate, then let them look for 
  5998. memory with the same name and communicate that way. 
  5999.  
  6000. Named Pipes 
  6001.  
  6002. Named pipes are a lot like shared memory, but think of a named pipe as a file 
  6003. instead of a single block of memory.  Each process can create, read, write, and 
  6004. destroy a named pipe, much like you can a file. 
  6005.  
  6006. The difference between named pipes and shared memory is that a named pipe link 
  6007. is hot; With shared memory, data can be left in (as a sleeper, if you will), 
  6008. process 1 exits, process 2 accesses the data in memory, then deallocates the 
  6009. memory.  With shared memory, a process doesn't even have to exist to leave a 
  6010. message for another process. 
  6011.  
  6012. Queues 
  6013.  
  6014. An OS/2 queue is either a standard First-In First-Out (FIFO) queue 
  6015. data/operation structure, a LIFO structure, or a user-based-priority structure. 
  6016. However, OS/2 makes it unique because more than one process (or thread) can 
  6017. write to this queue. 
  6018.  
  6019.  
  6020. Related Information:
  6021.  
  6022. What is the best way to communicate between threads?
  6023.  
  6024.  
  6025. ΓòÉΓòÉΓòÉ 9.20. What is the best way to communicate between threads? ΓòÉΓòÉΓòÉ
  6026.  
  6027. The best way to communicate between threads is sometimes also the best way to 
  6028. communicate between processes.  However, when communicating between threads you 
  6029. can utilize two (very important) techniques: 
  6030.  
  6031. Semaphores 
  6032.  
  6033. In order to share application resources, and not write to the same space at the 
  6034. same time, you have to have some kind of flags that tell the thread when it 
  6035. should stop, when it should keep on going, and so on. Semaphores provide this 
  6036. capability.  Semaphores are not for passing data.  They merely exist as simple 
  6037. flags between threads and you should treat them as such. 
  6038.  
  6039. Global Variables 
  6040.  
  6041. "Hey Jeff - I thought this was supposed to be about nifty OS/2-specific 
  6042. tricks!"  It is!  You can now use those old nasty things, global variables, in 
  6043. new ways.  In conjunction with semaphores, you can pass data very easily 
  6044. between threads with global variables.  Here's a simple example: 
  6045.  
  6046.  1. Create a global variable called PassData. 
  6047.  2. Create a semaphore called OkToPassData. 
  6048.  3. Create a semaphore called DataPassed. 
  6049.  4. Have two threads work at the same time: 
  6050.  
  6051.     a. If the semaphore DataPassed is true: 
  6052.  
  6053.        1. Set the semaphore OkToPassData to false. 
  6054.        2. Read the data in the global. 
  6055.        3. Set the semaphore DataPassed to false. 
  6056.        4. Set the semaphore OkToPassData to true. 
  6057.  
  6058.     b. When a thread wants to pass data, wait for the semaphore to be clear. 
  6059.     c. Set the semaphore OkToPassData to false. 
  6060.     d. Put the data in the global. 
  6061.     e. Set the semaphore DataPassed to true. 
  6062.     f. Set the semaphore OkToPassData to true. 
  6063.  
  6064. Of course, there are issues of deadlock and other such nonsense that corporate 
  6065. chaps get paid to consider, but that's beyond the scope of this document. 
  6066.  
  6067.  
  6068. Related Information:
  6069.  
  6070. What is the best way to communicate between processes?
  6071.  
  6072.  
  6073. ΓòÉΓòÉΓòÉ 9.21. How to I write an IFS? ΓòÉΓòÉΓòÉ
  6074.  
  6075. Starting with Issue #3, EDM/2 started carrying a series about writing an IFS. 
  6076.  
  6077.  
  6078. ΓòÉΓòÉΓòÉ 9.22. How do I interface with OS/2's SCSI support? ΓòÉΓòÉΓòÉ
  6079.  
  6080. A complete description and sample code can be found at ftp archive; 
  6081.  
  6082. reseq.regent.e-technik.tu-muenchen.de 
  6083.  
  6084. in /pub/comp/os/os2/drivers/source/scsipg.zip. 
  6085.  
  6086.  
  6087. ΓòÉΓòÉΓòÉ 9.23. How do I program full-screen graphics? ΓòÉΓòÉΓòÉ
  6088.  
  6089. Several compilers come with their own VGA graphics libraries.  A 3rd party 
  6090. developer has even developed an SVGA library (with drivers) for emx/gcc. 
  6091.  
  6092. Full-screen graphics programming is nearly identical to full-screen DOS 
  6093. graphics programming, with the notable exception that you must lock and unlock 
  6094. the screen under OS/2 before you can use it. 
  6095.  
  6096.  
  6097. ΓòÉΓòÉΓòÉ 9.24. How do I program MMPM/2 programs? ΓòÉΓòÉΓòÉ
  6098.  
  6099. IBM has created the MMPM/2 toolkit just for that.  However, if that is too much 
  6100. trouble for you, there is a simple REXX interface to MMPM/2 available in OS/2 
  6101. 2.1. 
  6102.  
  6103. IBM's Ultimedia Builder/2, Ultimedia Perfect Image/2, and Ultimedia Workplace/2 
  6104. are all in beta and scheduled to be released soon. 
  6105.  
  6106.  
  6107. ΓòÉΓòÉΓòÉ 9.25. How do I peripheral memory or an I/O port? ΓòÉΓòÉΓòÉ
  6108.  
  6109. The basic thing to do is either mark it as IOPL or surround it in a 16-bit 
  6110. module.    emx/gcc and other compilers include some macros and functions to assist 
  6111. you in doing this. 
  6112.  
  6113.  
  6114. ΓòÉΓòÉΓòÉ 10. Porting ΓòÉΓòÉΓòÉ
  6115.  
  6116. This section covers all aspects of porting programs. 
  6117.  
  6118.  
  6119. ΓòÉΓòÉΓòÉ 10.1. How do I port my DOS keyboard TSR to OS/2? ΓòÉΓòÉΓòÉ
  6120.  
  6121. Use keyboard monitors (for fullscreen sessions) or hooks for the PM session. 
  6122.  
  6123.  
  6124. ΓòÉΓòÉΓòÉ 10.2. How can I simulate (Unix feature) under OS/2? ΓòÉΓòÉΓòÉ
  6125.  
  6126.  1. fork 
  6127.  2. fork/exec 
  6128.  3. select 
  6129.  4. job control 
  6130.  
  6131. A working version of select() is included with the emx/gcc libraries. See the 
  6132. emx/gcc documentation for more information on its usage. 
  6133.  
  6134. A working version of fork() comes with the emx/gcc libraries.  The author 
  6135. cautions that this is not the way to multitask, though, because it eats up a 
  6136. lot of resources (since it literally duplicates the current process, leaving 
  6137. everything but the PID unchanged).  _beginthread() is the suggested solution if 
  6138. at all possible. 
  6139.  
  6140.  
  6141. ΓòÉΓòÉΓòÉ 10.3. How can I recompile public domain/shareware source code for OS/2? ΓòÉΓòÉΓòÉ
  6142.  
  6143. Most publicly available OS/2 programs come with binaries (since there is 
  6144. currently only one OS/2 architecture).  If you are porting source code from 
  6145. another system (for example, Unix), you will first need to acquire a compiler. 
  6146. See section 1 for information on compilers; in particular, note that the GNU C 
  6147. compiler is available. 
  6148.  
  6149. You should realize that many publicly available programs have already been 
  6150. ported to OS/2.  Check the many FTP sites carrying OS/2 programs before you 
  6151. reinvent any wheels (the OS/2 User's FAQ contains information on FTP site). 
  6152.  
  6153. Most Unix applications (through the use of emx/gcc) port with extreme ease; DOS 
  6154. and Windows applications are a tougher problem, and require many changes before 
  6155. they can be recompiled as a native OS/2 program. 
  6156.  
  6157. (It is interesting to note that MicroSoft C v6.0 will compile bound OS/2 
  6158. programs, which will run under DOS and OS/2 without modification.) 
  6159.  
  6160.  
  6161. Related Information:
  6162.  
  6163. How can I port my DOS program to OS/2?
  6164. How can I port my Windows program to OS/2?
  6165.  
  6166.  
  6167. ΓòÉΓòÉΓòÉ 10.4. How can I port my DOS program to OS/2? ΓòÉΓòÉΓòÉ
  6168.  
  6169. To the first approximation, you don't have to --- OS/2 2.x's DOS support is 
  6170. excellent, and your DOS program will probably just work; similarly, OS/2 2.x 
  6171. supports Windows 3.0 (and soon 3.1) programs.  See the OS/2 User's FAQ for 
  6172. details. 
  6173.  
  6174. [That was Barry Jaspan's opinion.  I believe that you should make every effort 
  6175. to recompile your existing DOS programs for OS/2 2.x.  They will run faster in 
  6176. many cases, and both (a) use less memory and (b) be able to use more memory 
  6177. than their DOS counterparts. - Jeff] 
  6178.  
  6179. If you truly want to port your DOS program over to OS/2, then study the 
  6180. libraries available to you.  The core code (if you wrote it correctly) will 
  6181. probably not change much.  You will just have to change the user interface 
  6182. stuff. 
  6183.  
  6184. If your program is a real simple one that uses standard input and output, then 
  6185. you will probably not make very many changes to your program when converting it 
  6186. to OS/2. 
  6187.  
  6188. You should also realize that neato and nifty DOS tricks (like grabbing an 
  6189. interrupt whenever you feel like it, or writing directly to almost anywhere) 
  6190. are completely out of the question. 
  6191.  
  6192.  
  6193. Related Information:
  6194.  
  6195. How can I port my Windows program to OS/2?
  6196.  
  6197.  
  6198. ΓòÉΓòÉΓòÉ 10.5. How can I port my Windows program to OS/2? ΓòÉΓòÉΓòÉ
  6199.  
  6200. A tool called Mirrors is available from Micrographx.  It does not currently 
  6201. support Windows 3.1-specific programs and calls.  (although you *can* call the 
  6202. functions in the new 3.1 DLLs) 
  6203.  
  6204. o Rough ports can be done in under 1 day, but a detailed port still costs you a 
  6205.   lot of effort. 
  6206. o The ported application is heavily dependent on the underlying OS/2 system. 
  6207.  
  6208. There are also several toolkits available that allow you to make calls to a 
  6209. common API library, and your source will work across the two platforms without 
  6210. any changes at all. 
  6211.  
  6212. However, if you want to bite the bullet and port it, then be prepared to make a 
  6213. lot of changes.  Just like porting regular DOS programs, you will have to scrap 
  6214. most, if not all, of your user interface.  Your core code, if modular and 
  6215. abstract enough, should come through the port relatively unscathed. 
  6216.  
  6217.  
  6218. Related Information:
  6219.  
  6220. How can I port my DOS program to OS/2?
  6221.  
  6222.  
  6223. ΓòÉΓòÉΓòÉ 11. Miscellaneous ΓòÉΓòÉΓòÉ
  6224.  
  6225. This section covers questions not covered in previous sections. 
  6226.  
  6227.  
  6228. ΓòÉΓòÉΓòÉ 11.1. Is OS/2 suitable for real time programs? ΓòÉΓòÉΓòÉ
  6229.  
  6230. Yes!  There is a special priority you can assign your programs 
  6231. (ForegroundServer Mode) via DosSetPriority() which will give your process 
  6232. (note, not thread, but process) the maximum allowable CPU time. 
  6233.  
  6234. Another route is to use DosEnterCritSec()/DosExitCritSec().  Calling the former 
  6235. will disable thread switching (hopefully for a short period of time), and 
  6236. calling the latter will enable thread switching again. 
  6237.  
  6238.  
  6239. ΓòÉΓòÉΓòÉ 11.2. What is available for multimedia programming under OS/2? ΓòÉΓòÉΓòÉ
  6240.  
  6241. The OS/2 2.x Multimedia package is now available.  Call the IBM Multimedia 
  6242. office at (800) 426-9402 ext. 150. 
  6243.  
  6244.  
  6245. ΓòÉΓòÉΓòÉ 11.3. What is available for AI/neural net programming under OS/2? ΓòÉΓòÉΓòÉ
  6246.  
  6247. LISP and XScheme are available from cdrom.com.  There are also some AI/neural 
  6248. net tools listed in tinf31.zip. 
  6249.  
  6250.  
  6251. Related Information:
  6252.  
  6253. Programming language availability
  6254.  
  6255.  
  6256. ΓòÉΓòÉΓòÉ 11.4. Special software offers ΓòÉΓòÉΓòÉ
  6257.  
  6258. Here are some of the OS/2 software products that represent particularly good 
  6259. values.  Most prices do not include shipping and handling. 
  6260.  
  6261. o Borland C++ for OS/2.  Available from Below Zero in Calgary (phone 
  6262.   800-461-2777, 403-547-0669, or FAX 403-547-1018) for about $136 U.S., 
  6263.   including shipping.  Add GST in Canada.  Below Zero will export outside North 
  6264.   America. 
  6265.  
  6266. o IBM PL/I.  Not everyone is a PL/I programmer, but IBM is offering free copies 
  6267.   of Workframe/2 with every purchase and free product videos. Phone 
  6268.   800-426-3346 ext. STL10 for more information on the two packages available. 
  6269.  
  6270. (Quoted almost directly from OS/2 General FAQ) 
  6271.  
  6272.  
  6273. ΓòÉΓòÉΓòÉ 11.5. Technical Support ΓòÉΓòÉΓòÉ
  6274.  
  6275. How can I get answers to my OS/2 questions? 
  6276.  
  6277. If your question is not answered in this List, post a note to the appropriate 
  6278. Usenet conference: 
  6279.  
  6280. Newsgroup                           Description 
  6281. comp.os.os2.apps                    carries discussions related to finding or 
  6282.                                     using any application running under OS/2 
  6283. comp.os.os2.networking              looks at networking issues 
  6284. comp.os.os2.advocacy                deals with opinions and speculation 
  6285. comp.os.os2.programmer.porting      helps programmers move applications over to 
  6286.                                     OS/2 from other operating systems and 
  6287.                                     environments 
  6288. comp.os.os2.programmer.misc         addresses anything else related to OS/2 
  6289.                                     programming 
  6290. comp.os.os2.beta                    explores beta releases of OS/2 
  6291. comp.os.os2.ver1x                   supports all releases of OS/2 prior to 
  6292.                                     Version 2.0 
  6293. comp.os.os2.announce                carries important OS/2 announcements 
  6294. comp.os.os2.bugs                    discusses possible bugs found in released 
  6295.                                     versions of the operating system 
  6296. comp.os.os2.multimedia              fosters conversation about OS/2 multimedia 
  6297.                                     (including MMPM/2), 
  6298. comp.os.os2.setup                   offers a place to talk about setup and 
  6299.                                     installation issues 
  6300. comp.os.os2.misc                    is for any other OS/2-related discussion 
  6301. comp.lang.rexx                      discusses REXX programming 
  6302.  
  6303. These groups are also watched closely by OS/2 experts from IBM. 
  6304.  
  6305. A LISTSERVer distributes its own OS/2 conference by mail; send a single line 
  6306. message with the word HELP to listserv@cc1.kuleuven.ac.be for full 
  6307. instructions; or send the same message to listserv@frors12.circe.fr for 
  6308. information on an unedited mailing list.  To subscribe to the Multimedia 
  6309. Presentation Manager/2, send a single line message with the phrase SUBSCRIBE 
  6310. MMOS2-L (Your Name) to mail-server@knex.via.mind.org. 
  6311.  
  6312. Your local FidoNet BBS may carry OS/2 echo conferences and/or OS2NET. If not, 
  6313. ask your system operator to join them.  CompuServe (FIND OS/2) and Prodigy are 
  6314. also excellent resources. 
  6315.  
  6316. The IBM PC Co. BBS's (modem 404-835-6600) message areas, product database, and 
  6317. PS/2 Assistant file(s) are invaluable resources. Information on the new OS/2 
  6318. BBS is included in the OS/2 2.0 package. In the United States IBM has toll free 
  6319. technical support (phone 800-237-5511), an OS/2 Hotline (general information, 
  6320. orders, upgrades, phone 800-3-IBM-OS2; ask about OS/2 videotapes, T-shirts, and 
  6321. other accessories), the HelpWare Center (phone 800-PS2-2227), a software order 
  6322. line (phone 800-IBM-CALL), two FAX information services (phone 800-IBM-4FAX 
  6323. and/or 800-IBM-3395), and an educational inquiries line (phone 800-222-7257). 
  6324. In Canada phone IBM Personal Systems Software at 800-465-1234. 
  6325.  
  6326. Any of the regular DOS or Windows resources (e.g. books, magazines, 
  6327. shareware/freeware sources) will be useful since both environments come with 
  6328. OS/2 2.0. 
  6329.  
  6330. (taken from OS/2 General FAQ) 
  6331.  
  6332.  
  6333. Related Information:
  6334.  
  6335. Developer's Assistance Program
  6336.  
  6337.  
  6338. ΓòÉΓòÉΓòÉ 11.6. Developer's Assistance Program (DAP) ΓòÉΓòÉΓòÉ
  6339.  
  6340. OS/2 2.0 developers should contact the IBM Developer Assistance Program (phone 
  6341. 407-982-6408); membership is free.  (You may also join on CompuServe with GO 
  6342. OS2DAP.)  The OS/2 Professional Developer's Kit CD-ROM, containing a wide 
  6343. selection of development tools and code, and the OS/2 2.1 Beta CD-ROM are both 
  6344. available from IBM (phone 800-3-IBM-OS2 to order in the United States for 
  6345. between $15 and $20 each, shipping included; in Canada, phone 800-465-1234; in 
  6346. Australia, phone Rohaini Cain or Mike Voris at 13-2426 ext. 7684; elsewhere, 
  6347. contact the International OS/2 User Group by phoning 285-641175 in the U.K.) 
  6348. The OS/2 Device Driver Development Kit CD-ROM is also now available from IBM. 
  6349. To order phone 407-982-4239 (FAX 407-982-4218) in North America, 61-2-354-7684 
  6350. (FAX 61-2-354-7766) in most of the Far East and Pacific Rim, 81-3-5563-5897 
  6351. (FAX 81-3-5563-4957) in Japan, 81-2-528-1548 (FAX 82-2-528-1414) in Korea, 
  6352. 011-52-627-1846 (FAX 011-52-395-7812) in Latin America, or +49-69-6645-3318 in 
  6353. Germany. 
  6354.  
  6355. (taken from the OS/2 general FAQ) 
  6356.  
  6357.  
  6358. ΓòÉΓòÉΓòÉ 12. OS/2 Software Sources ΓòÉΓòÉΓòÉ
  6359.  
  6360. The following BBSes hold large OS/2 libraries: 
  6361.  
  6362.  
  6363.  Name                      Number
  6364.  
  6365.  Fernwood                  (203) 483-0348
  6366.  
  6367.  OS/2 Shareware            (703) 385-4325
  6368.  
  6369.  Bay Area OS/2             (510) 657-7948
  6370.  
  6371.  Gateway/2                 (314) 554-9313
  6372.  
  6373.  Greater Chicago Online    (708) 895-4042
  6374.  
  6375.  OS/2 Connection (San      (619) 549-4215
  6376.  Diego)
  6377.  
  6378.  OS/2 Las Vegas            (702) 433-5535
  6379.  
  6380.  IBM Germany               049-711-785-777
  6381.  
  6382.  IBM Germany (Another)     +49-69-6645-325
  6383.  
  6384.  IBM Denmark               45-42-88-72-22
  6385.  
  6386.  OS/2 UK                   0454-633197
  6387.  
  6388.  IBM UK                    0256-336655
  6389.  
  6390.  IBM Norway                47-66-99-94-50
  6391.  
  6392.  OS/2 Norway               47-22-38-09-49
  6393.  
  6394.  OS/2 Australia            61-2-241-2466
  6395.  
  6396. (The monthly Worldwide OS/2 BBS Listing, available from these BBSes, lists 
  6397. others.)  The IBM PC Company BBS (modem 404-835-6600) has some 
  6398. shareware/freeware as well, along with CSDs and the PS/2 Assistant (an 
  6399. invaluable resource for locating almost any sort of information on OS/2). For 
  6400. information on IBM's new OS/2 BBS phone 800-547-1283.  IBM Canada maintains 
  6401. several support BBSes: 
  6402.  
  6403.    (416) 946-4255 
  6404.    (514) 938-3022 
  6405.    (604) 664-6464 
  6406.    (416) 946-4244 
  6407.  
  6408. The Usenet conference comp.binaries.os2 carries OS/2 software.  And several 
  6409. sites are available via anonymous ftp.  (No ftp?  Send a single line message 
  6410. with the word HELP to bitftp@pucc.bitnet or ftpmail@decwrl.dec.com to learn 
  6411. about ftp mail servers.)  Some are (with Internet node numbers and 
  6412. subdirectories): 
  6413.  
  6414.  
  6415.  Site                      IP Address      Home OS/2 Directory
  6416.  
  6417.  cdrom.com                 ???.???.???.??? os2
  6418.  
  6419.  ftp-os2.nmsu.edu          128.123.35.151  pub/os2
  6420.  hobbes.nmsu.edu
  6421.  
  6422.  software.watson.ibm.com   129.34.139.5    pub/os2
  6423.  
  6424.  mtsg.ubc.ca               137.82.27.1     os2
  6425.  
  6426.  access.usask.ca           128.233.3.1     pub/archives/os2
  6427.  
  6428.  luga.latrobe.edu.au       131.172.2.2     pub/os2
  6429.  
  6430.  funic.funet.fi            128.214.6.100   pub/os2
  6431.  
  6432.  pdsoft.lancs.ac.uk        148.88.64.2     micros/ibmpc/os2
  6433.  
  6434.  ftp.uni-stuttgart.de      129.69.1.12     soft/os2
  6435.  
  6436.  src.doc.ic.ac.uk          146.169.2.1     computing/systems/os2
  6437.  
  6438.  zaphod.cs.uwindsor.ca     137.207.224.3   pub/local/os2
  6439.  
  6440.  ftp.luth.se               130.240.18.2    pub/pc/os2
  6441.  
  6442. The cdrom.com library is available on CD-ROM from Walnut Creek (phone 
  6443. 510-947-5996).  EMS (phone 301-924-3594) offers an OS/2 shareware/freeware 
  6444. library on diskette. 
  6445.  
  6446. Other sources include CompuServe (FIND OS/2) and archive servers (send a single 
  6447. line message with the word HELP to listserv@cc1.kuleuven.ac.be or 
  6448. mail-server@rus.uni-stuttgart.de for more information, or use ftp). TRICKLE 
  6449. servers are also available outside the United States.  For more information on 
  6450. TRICKLE services, including automatic file subscription procedures, send a 
  6451. single line message with the word HELP to any one of the following sites 
  6452. nearest you: 
  6453.  
  6454. Country      Address 
  6455. Austria      TRICKLE@AWIWUW11.BITNET 
  6456. Belgium      TRICKLE@BANUFS11.BITNET 
  6457. Colombia     TRICKLE@UNALCOL.BITNET 
  6458. France       TRICKLE@FRMOP11.BITNET 
  6459. Germany      TRICKLE@DEARN.BITNET 
  6460. Israel       TRICKLE@TAUNIVM.BITNET 
  6461. Italy        TRICKLE@IMIPOLI.BITNET 
  6462. Netherlands  TRICKLE@HEARN.BITNET 
  6463. Sweden       TRICKLE@SEARN.BITNET 
  6464. Turkey       TRICKLE@TREARN.BITNET 
  6465.              TRICKLE@TRMETU.BITNET 
  6466.  
  6467. IBM has been releasing freely distributable employee written software (e.g. 
  6468. Visual REXX) and OS/2 patches to these sites. 
  6469.  
  6470. (The previous was taken almost verbatim from the OS/2 General FAQ) 
  6471.  
  6472.  
  6473. ΓòÉΓòÉΓòÉ 13. Bugs / Obtaining this FAQ / Contacting the Author ΓòÉΓòÉΓòÉ
  6474.  
  6475. Reporting Bugs and Errors in the FAQ 
  6476.  
  6477. With the advent of all this nifty hypertext IPF stuff, there are bound to be 
  6478. bugs and errors in this FAQ, simply by Murphy's Law.  (Anything that can go 
  6479. wrong, will go wrong)  If you find an error, however, insignificant, please 
  6480. send me a note (through one of the ways listed below) telling me what's wrong 
  6481. with the FAQ. 
  6482.  
  6483. Obtaining this FAQ 
  6484.  
  6485. This FAQ is distributed on a regular basis to: 
  6486.  
  6487.  1. cdrom.com, in /pub/os2/all/info/faq, on the Internet 
  6488.  
  6489. All other sites should receive this FAQ on a trickle-down basis from these 
  6490. sites. 
  6491.  
  6492. This FAQ is distributed in two versions, ASCII and INF.  The INF version is 
  6493. binary and viewable only by the VIEW.EXE program that comes with OS/2.  The 
  6494. ASCII version is text and is viewable by any program that can view text (which 
  6495. includes most word processors).  The filename is PFAQnn.ZIP, where 'nn' is the 
  6496. FAQ version. 
  6497.  
  6498. Contacting the Author 
  6499.  
  6500. I can be contacted in a multitude of ways: 
  6501.  
  6502. o Internet.  This is the preferred method.  E-mail me at 
  6503.   andreas@traci.almroth.pp.se. 
  6504.  
  6505. o Snail Mail 
  6506.  
  6507.    Andreas Almroth 
  6508.    Apelgatan 2, 2tr 
  6509.    S-602 15 Norrkoping 
  6510.    SWEDEN 
  6511.  
  6512.  
  6513. ΓòÉΓòÉΓòÉ 14. Credits ΓòÉΓòÉΓòÉ
  6514.  
  6515. The following people have contributed in numerous and not-so-numerous ways to 
  6516. this document to make it what it is today, and what it will be tomorrow.  Give 
  6517. a big round of applause for... 
  6518.  
  6519. o Barry Jaspan <bjaspan@athena.mit.edu> 
  6520. o Jeff Garzik <jgarzik@pantera.atl.ga.us> 
  6521. o Byers R E James <zoorejb@nusunix2.nus.sg> 
  6522. o Stefan Gruendal <Stefan_Gruendel@wue.maus.de> 
  6523. o Raja Thiagarajan <sthiagar@bronze.ucs.indiana.edu> 
  6524. o Larry Saloman <os2man@panix.com> 
  6525. o Timothy Sipples <sip1@kimbark.uchicago.edu> 
  6526. o Bob Smith <OECN_SMITH@MEC.OHIO.GOV> 
  6527. o Tim Francis <francis@vnet.IBM.COM> 
  6528. o Colin Jensen <cjensen@netcom.com> 
  6529. o Bill Henning <bhenning@wimsey.com> 
  6530. o Axel Uhl <auhl@fzi.de> 
  6531. o R. Mahoney <rmahoney@bix.com> 
  6532. o Frank Fuchs <ffu@softpro.de> 
  6533. o James J. Song <jjs@acd4.acd.com> 
  6534. o Mario Taneda <Mario_Taneda@ka.maus.de> 
  6535. o Timur Tabi <timur@seas.gwu.edu> 
  6536. o Paul Prescod <papresco@undergrad.math.uwaterloo.ca> 
  6537. o Rich Wales <richw@mks.com> 
  6538. o Craig Swanson <Craig_Swanson@f354.n202.z1.fidonet.org> 
  6539.  
  6540. Ok, so the list is a little short right now.  If you contributed to Barry's or 
  6541. Jeff's FAQ, and you are not listed here, then please send me your name and I'll 
  6542. be glad to include you in this list. 
  6543.  
  6544. I have obtained some information from sources other than people also. Besides 
  6545. being credited above, here is another list: 
  6546.  
  6547. o OS/2 Frequently Asked Questions List v2.1  (Available from cdrom.com in 
  6548.   os2/all/info/faq/faq21*.zip) 
  6549.  
  6550. o Electronic Developers' OS/2 Magazine  (Available from cdrom.com in 
  6551.   os2/all/info/edmi/*) 
  6552.